mindspore.ops.add
- mindspore.ops.add(input, other)[源代码]
逐元素计算两个输入tensor的和。
说明
两个输入不能同时为bool类型。[True, Tensor(True, bool_), Tensor(np.array([True]), bool_)]等都为bool类型。
支持广播,支持隐式类型转换、类型提升。
当输入为tensor时,维度应大于等于1。
- 参数:
input (Union[Tensor, number.Number, bool]) - 第一个输入tensor。
other (Union[Tensor, number.Number, bool]) - 第二个输入tensor。
- 返回:
Tensor
- 支持平台:
Ascend
GPU
CPU
样例:
>>> import mindspore >>> # case 1: x and y are both tensor. >>> x = mindspore.tensor([1., 2., 3.]) >>> y = mindspore.tensor([4., 5., 6.]) >>> output = mindspore.ops.add(x, y) >>> print(output) [5. 7. 9.] >>> # case 2: x is a scalar and y is a tensor >>> x = mindspore.tensor(1, mindspore.int32) >>> y = mindspore.tensor([4., 5., 6.]) >>> output = mindspore.ops.add(x, y) >>> print(output) [5. 6. 7.] >>> # the data type of x is int32, the data type of y is float32, >>> # and the output is the data format of higher precision float32. >>> print(output.dtype) Float32