torch.remainder¶
- torch.remainder(input, other, *, out=None) Tensor ¶
逐元素計算 Python 的模數運算。 結果與除數
other
的符號相同,並且其絕對值小於other
的絕對值。它也可以用
torch.div()
來定義為:torch.remainder(a, b) == a - a.div(b, rounding_mode="floor") * b
注意
不支援複數輸入。 在某些情況下,數學上不可能滿足具有複數的模數運算的定義。 請參閱
torch.fmod()
,以了解如何處理除以零的情況。另請參閱
torch.fmod()
,它實現了 C++ 的 std::fmod。 它是根據朝零方向捨入的除法來定義的。- 參數
- 關鍵字參數
out (Tensor, optional) – 輸出張量(可選)。
範例
>>> torch.remainder(torch.tensor([-3., -2, -1, 1, 2, 3]), 2) tensor([ 1., 0., 1., 1., 0., 1.]) >>> torch.remainder(torch.tensor([1, 2, 3, 4, 5]), -1.5) tensor([ -0.5000, -1.0000, 0.0000, -0.5000, -1.0000 ])