Tensorflow, how to multiply a 2D tensor (matrix) by corresponding elements in a 1D vector
问题 I have a 2D matrix M of shape [batch x dim] , I have a vector V of shape [batch] . How can I multiply each of the columns in the matrix by the corresponding element in the V? That is: I know an inefficient numpy implementation would look like this: import numpy as np M = np.random.uniform(size=(4, 10)) V = np.random.randint(4) def tst(M, V): rows = [] for i in range(len(M)): col = [] for j in range(len(M[i])): col.append(M[i][j] * V[i]) rows.append(col) return np.array(rows) In tensorflow,