快捷方式

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 的完整开发者文档

查看文档

教程

获取针对初学者和高级开发者的深度教程

查看教程

资源

查找开发资源并获得问题解答

查看资源