I have two relatively similar operations I'd like to figure out how to do.
The first is the simpler. I have a numpy array like
[[a,b,c,d],
[e,f,g,h],
[i,j,k,l]]
I would like to sum the columns to yield:
[6,12,18,24]
I know that I can do this with a for loop:
for i in range(0,ROW_LENGTH): #ROW_LENGTH defined elsewhere
listsum[i]=list[:,i].sum()
But this can't be the pythonic way, can it?
The second task is I need to do something similar with a 3D array. I assume the solution to this will be similar. A simple example is:
[[[a,b,c],[d,e,f],[g,h,i]],
[[j,k,l],[m,n,o],[p,q,r]],
[[s,t,u],[v,w,x],[y,z,_]]]
Where the output should be:
[[a+j+s,b+k+t,c+l+u],[d+m+v,e+n+w,f+o+x],[g+p+y,h+q+z,i+r+_]]
I'm hopeful that understanding the technique for both of these will be a major boon, generally speaking, for how well I grasp python!
I'm going to link here to a separate question I'm asking for the same project:
axisparameter innp.sum? It allows you to perform these operation very efficiently.