bmm

paddle. bmm ( x, y, name=None ) [source]

Applies batched matrix multiplication to two tensors.

Both of the two input tensors must be three-dementional and share the same batch size.

if x is a (b, m, k) tensor, y is a (b, k, n) tensor, the output will be a (b, m, n) tensor.

Parameters
  • x (Tensor) – The input Tensor.

  • y (Tensor) – The input Tensor.

  • name (str|None) – A name for this layer(optional). If set None, the layer will be named automatically.

Returns

The product Tensor.

Return type

Tensor

Examples

import paddle

# In imperative mode: # size x: (2, 2, 3) and y: (2, 3, 2) x = paddle.to_tensor([[[1.0, 1.0, 1.0],

System Message: ERROR/3 (/usr/local/lib/python3.8/site-packages/paddle/tensor/linalg.py:docstring of paddle.tensor.linalg.bmm, line 25)

Unexpected indentation.

[2.0, 2.0, 2.0]],

System Message: WARNING/2 (/usr/local/lib/python3.8/site-packages/paddle/tensor/linalg.py:docstring of paddle.tensor.linalg.bmm, line 26)

Block quote ends without a blank line; unexpected unindent.

[[3.0, 3.0, 3.0],

[4.0, 4.0, 4.0]]])

System Message: WARNING/2 (/usr/local/lib/python3.8/site-packages/paddle/tensor/linalg.py:docstring of paddle.tensor.linalg.bmm, line 28)

Block quote ends without a blank line; unexpected unindent.

y = paddle.to_tensor([[[1.0, 1.0],[2.0, 2.0],[3.0, 3.0]],

[[4.0, 4.0],[5.0, 5.0],[6.0, 6.0]]])

System Message: WARNING/2 (/usr/local/lib/python3.8/site-packages/paddle/tensor/linalg.py:docstring of paddle.tensor.linalg.bmm, line 30)

Definition list ends without a blank line; unexpected unindent.

out = paddle.bmm(x, y) #output size: (2, 2, 2) #output value: #[[[6.0, 6.0],[12.0, 12.0]],[[45.0, 45.0],[60.0, 60.0]]] out_np = out.numpy()