快捷方式

torch.addcdiv

torch.addcdiv(input, tensor1, tensor2, *, value=1, out=None) Tensor

執行 tensor1tensor2 的逐元素相除,將結果乘以標量 value 並加到 input 上。

警告

addcdiv 的整數除法不再受支援,並且在未來版本中,addcdiv 將對 tensor1 和 tensor2 執行真正的除法。對於整數輸入,歷史上的 addcdiv 行為可以透過 (input + value * torch.trunc(tensor1 / tensor2)).to(input.dtype) 實現;對於浮點數輸入,則透過 (input + value * tensor1 / tensor2) 實現。未來 addcdiv 的行為將僅是後一種實現:(input + value * tensor1 / tensor2),適用於所有資料型別。

outi=inputi+value×tensor1itensor2i\text{out}_i = \text{input}_i + \text{value} \times \frac{\text{tensor1}_i}{\text{tensor2}_i}

inputtensor1tensor2 的形狀必須是可廣播的

對於型別為 FloatTensorDoubleTensor 的輸入,value 必須是實數,否則必須是整數。

引數
  • input (Tensor) – 要相加的張量

  • tensor1 (Tensor) – 分子張量

  • tensor2 (Tensor) – 分母張量

關鍵字引數
  • value (Number, optional) – tensor1 / tensor2 的乘數

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

示例

>>> t = torch.randn(1, 3)
>>> t1 = torch.randn(3, 1)
>>> t2 = torch.randn(1, 3)
>>> torch.addcdiv(t, t1, t2, value=0.1)
tensor([[-0.2312, -3.6496,  0.1312],
        [-1.0428,  3.4292, -0.1030],
        [-0.5369, -0.9829,  0.0430]])

文件

查閱 PyTorch 的完整開發者文件

檢視文件

教程

獲取針對初學者和高階開發者的深度教程

檢視教程

資源

查詢開發資源並獲得問題解答

檢視資源