I want to multiply two 3D tensors in a specific way.
The two tensors have shapes T1 = (a,b,c)
and T2 = (d,b,c)
.
What I want is to multiply a
times T2
by the successive 'slices' (b,c)
of a
.
In other words, I want to have the same as this code :
import numpy as np
a=2
b=3
c=4
d=5
T1 = np.random.rand(a,b,c)
T2 = np.random.rand(d,b,c)
L= []
for j in range(a) :
L+=[T1[j,:,:]*T2]
L = np.array(L)
L.shape
I have the iterative solution and I try with axes arguments but I didn't succeed in the second way.
Since the shapes:
produce a:
Let's try a
broadcasted
pair of arrays:Shape and values match:
tensordot
,dot
, ormatmul
don't apply; just plain elementwise multiplication, withbroadcasting
.