評價此頁

torch.floor_divide#

torch.floor_divide(input, other, *, out=None) Tensor#

注意

在 PyTorch 1.13 之前,torch.floor_divide() 會錯誤地執行截斷除法。要恢復之前的行為,請使用 rounding_mode='trunc'torch.div()

計算 input 除以 other 的逐元素結果,並將結果向下取整。

outi=floor(inputiotheri)\text{{out}}_i = \text{floor} \left( \frac{{\text{{input}}_i}}{{\text{{other}}_i}} \right)

支援廣播到公共形狀、型別提升以及整數和浮點數輸入。

引數
  • input (TensorNumber) – 被除數

  • other (TensorNumber) – 除數

關鍵字引數

out (Tensor, optional) – 輸出張量。

示例

>>> a = torch.tensor([4.0, 3.0])
>>> b = torch.tensor([2.0, 2.0])
>>> torch.floor_divide(a, b)
tensor([2.0, 1.0])
>>> torch.floor_divide(a, 1.4)
tensor([2.0, 2.0])