捷徑

torch.addcmul

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

執行 tensor1tensor2 逐元素的乘法,將結果乘以純量 value,然後加到 input

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

tensortensor1tensor2 的形狀必須是 可廣播的 (broadcastable)

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

參數
  • input (Tensor) – 要被加上的張量

  • tensor1 (Tensor) – 要被乘上的張量

  • tensor2 (Tensor) – 要被乘上的張量

關鍵字參數
  • value (Number, optional) – tensor1.tensor2tensor1 .* tensor2 的乘數

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

範例

>>> t = torch.randn(1, 3)
>>> t1 = torch.randn(3, 1)
>>> t2 = torch.randn(1, 3)
>>> torch.addcmul(t, t1, t2, value=0.1)
tensor([[-0.8635, -0.6391,  1.6174],
        [-0.7617, -0.5879,  1.7388],
        [-0.8353, -0.6249,  1.6511]])

文件

存取 PyTorch 的全面開發者文件

檢視文件

教學

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

檢視教學

資源

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

檢視資源