mindspore.ops.matmul

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

Return the matrix product of two tensors.

Note

  • input and other must have same data type, and both of them must be not scalar and support broadcast.

  • On Ascend, the rank of input or other must be between 1 and 6.

  • input and other must not be empty tensor when executing the backward process for dynamic shape case in JIT mode.

Parameters
  • input (Tensor) – The first input tensor.

  • other (Tensor) – The second input tensor.

Returns

Tensor or scalar

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> # case 1 : Reasonable application of broadcast mechanism.
>>> input = mindspore.ops.arange(24, dtype=mindspore.float32).reshape(2, 3, 4)
>>> other = mindspore.ops.arange(20, dtype=mindspore.float32).reshape(4, 5)
>>> output = mindspore.ops.matmul(input, other)
>>> print(output)
[[[  70.   76.   82.   88.   94.]
  [ 190.  212.  234.  256.  278.]
  [ 310.  348.  386.  424.  462.]]
 [[ 430.  484.  538.  592.  646.]
  [ 550.  620.  690.  760.  830.]
  [ 670.  756.  842.  928. 1014.]]]
>>>
>>> # case 2 : The rank of `input` is 1.
>>> input = mindspore.ops.ones(([1, 2]))
>>> other = mindspore.ops.ones(([2]))
>>> output = mindspore.ops.matmul(input, other)
>>> print(output)
[2.]