mindspore.ops.bmm

mindspore.ops.bmm(input_x, mat2)[源代码]

基于batch维度的两个Tensor的矩阵乘法。

output[...,:,:]=matrix(x[...,:,:])matrix(y[...,:,:])

input_x 的维度不能小于 3mat2 的维度不能小于 2

参数:
  • input_x (Tensor) - 输入相乘的第一个Tensor。其shape为 (B,N,C) ,其中 B 表示批处理大小,可以是多维度, NC 是最后两个维度的大小。

  • mat2 (Tensor) - 输入相乘的第二个Tensor。Tensor的shape为 (B,C,M)

返回:

Tensor,输出Tensor的shape为 (B,N,M)

异常:
  • ValueError - input_x 的维度小于 3 或者 mat2 的维度小于2。

  • ValueError - input_x 第三维的长度不等于 mat2 第二维的长度。

支持平台:

Ascend GPU CPU

样例:

>>> input_x = Tensor(np.ones(shape=[2, 4, 1, 3]), mindspore.float32)
>>> mat2 = Tensor(np.ones(shape=[2, 4, 3, 4]), mindspore.float32)
>>> output = ops.bmm(input_x, mat2)
>>> print(output)
[[[[3. 3. 3. 3.]]
  [[3. 3. 3. 3.]]
  [[3. 3. 3. 3.]]
  [[3. 3. 3. 3.]]]
 [[[3. 3. 3. 3.]]
  [[3. 3. 3. 3.]]
  [[3. 3. 3. 3.]]
  [[3. 3. 3. 3.]]]]