I have a question regarding the deletion from arrays. I have a 3-D numpy array (coordinates are z,y,x) with an estimated 900^3 size. Only a few values are nonzero, but they have a nontrivial spatial distribution. I want to delete all 2-D slices in that array which have only zeros in it. In other words, I want an array with minimum size which still has all relevant data in it.
My attempt looks like:
while np.all(a[0]==0):
a=np.delete(a,0,0)
while np.all(a[a.shape[0]-1]==0) and a.shape[0]>1:
a=np.delete(a,-1,0)
and seems to work for the z-direction. How can I do something equal in the other two directions? And is there maybe another way of doing it better?
Another Idea was
tmp=np.delete(tmp,np.all(tmp==0,axis=1),1)
but that one seems to work only from the start and leaves out the zeros at the end.
Is it maybe possible, to rotate an array in 3D space?