mindspore.ops.Add
- class mindspore.ops.Add[源代码]
两个输入Tensor逐元素相加。
更多参考详见
mindspore.ops.add()
。- 输入:
- 输出:
Tensor,shape与输入 x、 y 广播后的shape相同,数据类型为两个输入中精度较高的类型。
- 支持平台:
Ascend
GPU
CPU
样例:
>>> # case 1: x and y are both Tensor. >>> add = ops.Add() >>> x = Tensor(np.array([1, 2, 3]).astype(np.float32)) >>> y = Tensor(np.array([4, 5, 6]).astype(np.float32)) >>> output = add(x, y) >>> print(output) [5. 7. 9.] >>> # case 2: x is a scalar and y is a Tensor >>> add = ops.Add() >>> x = Tensor(1, mindspore.int32) >>> y = Tensor(np.array([4, 5, 6]).astype(np.float32)) >>> output = 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