mindspore.ops.BatchMatMul
- class mindspore.ops.BatchMatMul(transpose_a=False, transpose_b=False)[source]
Computes matrix multiplication between two tensors by batch.
The two input tensors must have the same rank and the rank must be not less than 3.
- Parameters
- Inputs:
x (Tensor) - The first tensor to be multiplied. The shape of the tensor is
, where represents the batch size which can be multidimensional, and are the size of the last two dimensions. If transpose_a is True, its shape must be .y (Tensor) - The second tensor to be multiplied. The shape of the tensor is
. If transpose_b is True, its shape must be .
- Outputs:
Tensor, the shape of the output tensor is
.
- Raises
TypeError – If transpose_x or transpose_y is not a bool.
ValueError – If length of shape of x is not equal to length of shape of y or length of shape of x is less than 3.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> x = Tensor(np.ones(shape=[2, 4, 1, 3]), mindspore.float32) >>> y = Tensor(np.ones(shape=[2, 4, 3, 4]), mindspore.float32) >>> batmatmul = ops.BatchMatMul() >>> output = batmatmul(x, y) >>> 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.]]]] >>> x = Tensor(np.ones(shape=[2, 4, 3, 1]), mindspore.float32) >>> y = Tensor(np.ones(shape=[2, 4, 3, 4]), mindspore.float32) >>> batmatmul = ops.BatchMatMul(transpose_a=True) >>> output = batmatmul(x, y) >>> 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.]]]]