I need elementwise multiplication between a 3 dimensional array and a vector. I understand broadcasting is not yet supported in pytorch so i select a single element from my vector in a for loop as float(my_vector.data.numpy()[i]) and multiply it by slicing 2d arrays from my 3d matrix.
I need to update both the 3d arrary and the vector using the gradient. But when i call backward on my loss, only the 3d array’s grad attribute is populated with gradients and the vector’s grad attribute is left untouched. I am guessing this is because of the weird way i am accessing elements from the vector for multiplication (not sure though). The problem was that torch.mul either supports passing a float value or scalar multiplication ot a FloatTensor for element wise multiplication. Can someone suggest a modification for my code so that the gradients for the vector are also computed?