mindspore.ops.matmul

查看源文件
mindspore.ops.matmul(input, other)[源代码]

计算两个输入的矩阵乘积。

说明

  • inputother 的数据类型必须一致,不支持Scalar,两者须支持广播。

  • Ascend平台, inputother 的秩必须在 1 到 6 之间。

  • 执行反向时,inputother 在即时编译模式动态shape场景下不支持空tensor。

参数:
  • input (Tensor) - 第一个输入tensor。

  • other (Tensor) - 第二个输入tensor。

返回:

Tensor或Scalar

支持平台:

Ascend GPU CPU

样例:

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