快速鍵

torch.addcdiv

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

執行 tensor1 除以 tensor2 的逐元素除法,將結果乘以純量 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\text{tensor1} / \text{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 的完整開發者文件

檢視文件

教學

取得初學者和進階開發者的深入教學

檢視教學

資源

尋找開發資源並取得問題解答

檢視資源