Column-wise matrix multiplication

I have an M x N matrix and would like to multiply each M x 1 column by an L x M matrix with learnable elements, yielding N L-dimensional vectors. Is there a simple way to do this, something like * but for matrix multiplication? Bonus: Iā€™d ultimately like to return an (N.L) stacked vector where each column multiplication is stacked on top of each other. Any help to do this simply (and such that gradients can pass through these operators) would be amazing :ok_hand:t2:

It sounds like a normal matrix multiplication?

M, N, L = 3, 4, 5
input = torch.rand(M, N).float()
weight = nn.Parameter(torch.rand(L, M).float(), True)
result =, input).t()
1 Like