I have a Vector, M, with size N and a Tensor, d, with size NxNxD.
My aim is to perform the matrix multication M*d[i,:,:] for each i to get a new matrix with size nxD.
Now I could just do it like this:
a = np.zeros((n,D))
for i in range(n):
a[i] = G*np.matmul(M,d[i,:,:])
but I'd prefer a one line solution if it exists. Anyone got any ideas?
.apply()to execute function on every row or column.torch,tensorflowor other module for tensor.numpyis perfectly capable of dealing with tensors, and you definitely shouldn't use a comprehension.numpymay do it directly but I don't knownumpythat well to do it :) So I suggested other methods.