mindspore.ops.mul
- mindspore.ops.mul(input, other)[源代码]
两个Tensor逐元素相乘。
说明
当两个输入具有不同的shape时,它们的shape必须能够广播为一个共同的shape。
两个输入不能同时为bool类型。[True, Tensor(True, bool_), Tensor(np.array([True]), bool_)]等都属于bool类型。
支持隐式类型转换、类型提升。
- 参数:
input (Union[Tensor, number.Number, bool]) - 第一个输入。
other (Union[Tensor, number.Number, bool]) - 第二个输入。
- 返回:
Tensor
- 支持平台:
Ascend
GPU
CPU
样例:
>>> case 1: The shape of two inputs are different >>> import mindspore >>> x = mindspore.tensor([1.0, 2.0, 3.0], mindspore.float32) >>> output = mindspore.ops.mul(x, 100) >>> print(output) [100. 200. 300.] >>> case 2: The shape of two inputs are the same >>> import mindspore >>> x = mindspore.tensor([1.0, 2.0, 3.0], mindspore.float32) >>> y = mindspore.tensor([4.0, 5.0, 6.0], mindspore.float32) >>> output = mindspore.ops.mul(x, y) >>> print(output) [ 4. 10. 18.]