I know there are many questions about tensordot, and I've skimmed some of the 15 page mini-book answers that people I'm sure spent hours making, but I haven't found an explanation of what axes=2
does.
This made me think that np.tensordot(b,c,axes=2) == np.sum(b * c)
, but as an array:
b = np.array([[1,10],[100,1000]])
c = np.array([[2,3],[5,7]])
np.tensordot(b,c,axes=2)
Out: array(7532)
But then this failed:
a = np.arange(30).reshape((2,3,5))
np.tensordot(a,a,axes=2)
If anyone can provide a short, concise explanation of np.tensordot(x,y,axes=2)
, and only axes=2
, then I would gladly accept it.
In my previous post I deduced that
axis=2
translates toaxes=([-2,-1],[0,1])
How does numpy.tensordot function works step-by-step?
So that's trying to do a double axis reduction on the last 2 dimensions of the first
a
, and the first 2 dimensions of the seconda
. With thisa
that's a dimensions mismatch. Evidently thisaxes
was intended for 2d arrays, without much thought given to 3d ones. It is not a 3 axis reduction.These single digit axes values are something that some developer thought would be convenient, but that does not mean they were rigorously thought out or tested.
The tuple axes gives you more control: