Your 3d array (renamed from tensor
):
In [448]: arr.shape
Out[448]: (4, 5, 6)
vectosList
as array is 2d:
In [449]: np.array(vectorList).shape
Out[449]: (3, 6)
And your results, as array, is 4d:
In [450]: np.array(results).shape
Out[450]: (3, 4, 5, 6)
Thanks for giving a nice diverse set of dimensions. It's easier to track them that way.
We can produce the same 4d array with broadcasting. I've included all the ':' just to highlight how dimensions are paired:
In [451]: res = np.array(vectorList)[:,None,None,:]*arr[None,:,:,:]
In [452]: res.shape
Out[452]: (3, 4, 5, 6)
In [453]: np.allclose(res, np.array(results))
Out[453]: True
res=np.array(vectorList)[:,None,None]*arr
is the same thing.
A deleted answer suggested einsum
, the correct expression is np.einsum('il,jkl->ijkl',vectorList, arr)
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…