mm

paddle. mm ( input, mat2, name=None ) [source]

Applies matrix multiplication to two tensors.

Currently, the input tensors’ rank can be any, but when the rank of any inputs is bigger than 3, this two inputs’ rank should be equal.

Also note that if the raw tensor \(x\) or \(mat2\) is rank-1 and nontransposed, the prepended or appended dimension \(1\) will be removed after matrix multiplication.

This op does not support broadcasting. See paddle.matmul.

Parameters
  • input (Tensor) – The input tensor which is a Tensor.

  • mat2 (Tensor) – The input tensor which is a Tensor.

  • name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name

Returns

The product Tensor.

Return type

Tensor

Examples

import paddle
input = paddle.arange(1, 7).reshape((3, 2)).astype('float32')
mat2 = paddle.arange(1, 9).reshape((2, 4)).astype('float32')
out = paddle.mm(input, mat2)
print(out)
#        [[11., 14., 17., 20.],
#         [23., 30., 37., 44.],
#         [35., 46., 57., 68.]])