mindspore.numpy.matmul
- mindspore.numpy.matmul(x1, x2, dtype=None)[源代码]
Returns the matrix product of two arrays.
说明
Numpy arguments out, casting, order, subok, signature, and extobj are not supported. On GPU, the supported dtypes are np.float16 and np.float32. On CPU, the supported dtypes are np.float16 and np.float32.
- 参数
x1 (Tensor) – Input tensor, scalar not allowed.
x2 (Tensor) – Input tensor, scalar not allowed.
dtype (
mindspore.dtype
, optional) – Default:None
. Overrides the dtype of the output Tensor.
- 返回
Tensor or scalar, the matrix product of the inputs. This is a scalar only when both x1, x2 are 1-d vectors.
- 异常
ValueError – If the last dimension of x1 is not the same size as the second-to-last dimension of x2, or if a scalar value is passed in.
- Supported Platforms:
Ascend
GPU
CPU
样例
>>> import mindspore.numpy as np >>> x1 = np.arange(2*3*4).reshape(2, 3, 4).astype('float32') >>> x2 = np.arange(4*5).reshape(4, 5).astype('float32') >>> output = np.matmul(x1, x2) >>> 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.]]]