I've been using np.tensordot
in the past without any problems, but my current example, I struggle to understand the result.
For np.tensordot(d * y, r, axes=((1, 2, 3), (2, 3, 4))).shape
, I would expect a shape of (6, 5)
, but instead, I get (6, 6, 5)
. When I would run tensordot
6 times on axis0, I would however get the expected result, but I'd rather have tensordot
do this for me in one call. What's wrong with this?
>>> import numpy as np
>>> d = np.random.rand(6, 7, 1, 2)
>>> y = np.random.rand(6, 7, 1, 2)
>>> r = np.random.rand(6, 5, 7, 1, 2) > 0.5
>>>
>>> np.tensordot(d * y, r, axes=((1, 2, 3), (2, 3, 4))).shape
(6, 6, 5)
>>> np.tensordot((d * y)[0], r[0], axes=((0, 1, 2), (1, 2, 3))).shape
(5,)
>>> np.tensordot((d * y)[1], r[1], axes=((0, 1, 2), (1, 2, 3))).shape
(5,)
>>> np.tensordot((d * y)[2], r[2], axes=((0, 1, 2), (1, 2, 3))).shape
(5,)
...
>>> np.tensordot((d * y)[5], r[5], axes=((0, 1, 2), (1, 2, 3))).shape
(5,)