mindspore.ops.mm

mindspore.ops.mm(input, mat2)[source]

Returns the matrix product of two arrays. If input is a \((n \times m)\) Tensor, mat2 is a \((m \times p)\) Tensor, out will be a \((n \times p)\) Tensor.

Note

  • This function cannot support broadcasting. Refer to mindspore.ops.matmul() instead if you need a broadcastable function.

  • On Ascend, float64 doesn’t be supported.

Parameters
  • input (Tensor) – The first matrix of matrix multiplication. The last dimension of input must be the same size as the first dimension of mat2.

  • mat2 (Tensor) – The second matrix of matrix multiplication. The last dimension of input must be the same size as the first dimension of mat2.

Returns

Tensor or scalar, the matrix product of the inputs.

Raises
  • ValueError – If the last dimension of input is not the same size as the second-to-last dimension of mat2.

  • ValueError – If input or mat2 is not a Tensor.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore as ms
>>> import mindspore.ops as ops
>>> import numpy as np
>>> x1 = ms.Tensor(np.random.rand(2, 3), ms.float32)
>>> x2 = ms.Tensor(np.random.rand(3, 4), ms.float32)
>>> out = ops.mm(x1, x2)
>>> print(out.shape)
(2, 4)