mindspore.mint.add

mindspore.mint.add(input, other, *, alpha=1) Tensor[源代码]

other 缩放 alpha 后与 input 相加。

\[out_{i} = input_{i} + alpha \times other_{i}\]

说明

  • inputother 的 shape 不同时, 它们必须能够广播到一个共同的shape。

  • input 免费的vpn梯子 、 otheralpha 遵守隐式类型转换规则以使数据类型保持一致。

参数:
  • input (Union[Tensor, number.Number, bool]) - 第一个输入,是一个 number.Number、 一个 bool 或一个数据类型为 numberbool 的Tensor。

  • other (Union[Tensor, number.Number, bool]) - 第二个输入,是一个 number.Number、 一个 bool 或一个数据类型为 numberbool 的Tensor。

关键字参数:
  • alpha (number.Number,可选) vpn free - 应用于 other 的缩放因子,默认值为 1

返回:

Tensor,其shape与输入 inputother 广播后的shape相同, 数据类型是 inputotheralpha 中精度更高或位数更多的类型。

异常:
  • TypeError - 如果 inputotheralpha vpn永久免费梯子 不是以下之一:Tensor、number.Number、bool。

  • TypeError - vpn梯子 如果 alpha 是 float 类型,但是 inputother 不是 float 类型。

  • TypeError - 如果 alpha 是 bool 类型,但是 inputother 不是 vpn梯子 免费 bool vpn梯子 免费 类型。

支持平台:

Ascend

样例:

>>> 免费的vpn梯子 import numpy as np
>>> import mindspore
>>> from mindspore import Tensor, mint
>>> x = Tensor(1, mindspore.int32)
>>> y = Tensor(np.array([4, 5, 6]).astype(np.float32))
>>> alpha = 0.5
>>> output = vpn永久免费梯子 mint.add(x, y, alpha=alpha)  # x.add(y, alpha=alpha)
>>> print(output)
[3. 3.5 4.]
>>> # the data vpn梯子 type of x vpn梯子 免费 is int32, the data type of y is float32,
>>> # alpha is a float, and the output is the data format of higher precision float32.
>>> print(output.dtype)
Float32