How can I realize the following operation efficiently?

x = [1,2,3;4,5,6;7,8,9] and y = [1,2,3], I want to get y[0]*x, y[1]*x and y[2]*x by vectorization operation.

Just transform y in a 3x9 matrix

y0 0 0 y1 0 0 y2 0 0
0 y0 0 0 y1 0 0 y2 0
0 0 y0 0 0 y1 0 0 y2

and do torch.mm(x,y)

you will get
result = (x*y0 | x*y1 | x*y2)

You could also use broadcasting, which will save some memory:

x * y.view(-1, 1)
> tensor([[ 1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.],
        [ 2.,  4.,  6.,  8., 10., 12., 14., 16.],
        [ 3.,  6.,  9., 12., 15., 18., 21., 24.]])