I'm trying to take a tensor dot product in numpy using tensordot, but I'm not sure how I should reshape my arrays to achieve my computation. (I'm still new to the mathematics of tensors, in general.)
I have
arr = np.array([[[1, 1, 1],
[0, 0, 0],
[2, 2, 2]],
[[0, 0, 0],
[4, 4, 4],
[0, 0, 0]]])
w = [1, 1, 1]
And I want to take a dot product along axis=2, such that I have the matrix
array([[3, 0, 6],
[0, 12, 0]])
What's the proper numpy syntax for this? np.tensordot(arr, [1, 1, 1], axes=2) seems to raise a ValueError.
w = [1,2,3], just to have some variety there. - Divakarw = [1,1,1]to make it obvious that we're just trying to add up the elements inside each of the inner dimensions. - hlin117w = [1,1,1], then it's just adding elements alongaxis=2inarr. So, with that specificw, you don't really need any dot product and could just sum elements ofarralongaxis=2. - Divakar