I have 2 numpy arrays.
One is a 2*2 array.
a = [[1,2],[3,4]]
The other is a 2*2*4 array.
b = [[[0,0,0,0],[0,0,0,0]],[[0,0,0,0],[0,0,0,0]]]
I want to add them so that I have a 2*2*4 array, c.
c = [[[1,0,0,0],[2,0,0,0]],[[3,0,0,0],[4,0,0,0]]]
What’s the correct numpythonic way to do this?
Edit: This appears to work
b[:,:,:1]+=a[:,:,np.newaxis]
Not sure whether you can do the sum in one single steps. Here it is in two steps: