import torch # Define two 3D tensors with shapes (2, 3, 4) and (2, 4, 5) a = torch.randn(2, 3, 4) b = torch.randn(2, 4, 5) # Perform a batch matrix multiplication of the two tensors c = torch.bmm(a, b) print(c.shape) #Output: torch.Size([2, 3, 5])
import torch # Define two 3D tensors with shapes (2, 5, 10) and (2, 10, 8) a = torch.randn(2, 5, 10) b = torch.randn(2, 10, 8) # Perform a batch matrix multiplication of the two tensors c = torch.bmm(a, b) print(c.shape) #Output: torch.Size([2, 5, 8])In this example, we define two 3D tensors of shape (2, 5, 10) and (2, 10, 8). We use the torch.bmm() function to perform a batch matrix multiplication of the two tensors, resulting in a new tensor of shape (2, 5, 8).