mindspore.ops.mul

View Source On Gitee
mindspore.ops.mul(input, other)[source]

Multiplies two tensors element-wise.

outi=inputiotheri

Note

  • When the two inputs have different shapes, they must be able to broadcast to a common shape.

  • The two inputs can not be bool type at the same time, [True, Tensor(True, bool_), Tensor(np.array([True]), bool_)] are all considered bool type.

  • Support implicit type conversion and type promotion.

Parameters
  • input (Union[Tensor, number.Number, bool]) – The first input.

  • other (Union[Tensor, number.Number, bool]) – The second input.

Returns

Tensor

Supported Platforms:

Ascend GPU CPU

Examples

>>> # 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.]