Lets say you have a 5x5x5 numpy array
a = np.ones((5,5,5))
a[:,3,:] = 0
a[:,:,3] = 0
(I know it is ugly)
This returns
[[[1. 1. 1. 0. 1.]
[1. 1. 1. 0. 1.]
[1. 1. 1. 0. 1.]
[0. 0. 0. 0. 0.]
[1. 1. 1. 0. 1.]]
[[1. 1. 1. 0. 1.]
[1. 1. 1. 0. 1.]
[1. 1. 1. 0. 1.]
[0. 0. 0. 0. 0.]
[1. 1. 1. 0. 1.]]
[[1. 1. 1. 0. 1.]
[1. 1. 1. 0. 1.]
[1. 1. 1. 0. 1.]
[0. 0. 0. 0. 0.]
[1. 1. 1. 0. 1.]]
[[1. 1. 1. 0. 1.]
[1. 1. 1. 0. 1.]
[1. 1. 1. 0. 1.]
[0. 0. 0. 0. 0.]
[1. 1. 1. 0. 1.]]
[[1. 1. 1. 0. 1.]
[1. 1. 1. 0. 1.]
[1. 1. 1. 0. 1.]
[0. 0. 0. 0. 0.]
[1. 1. 1. 0. 1.]]]
What i want to do is to remove all rows and columns on all axis that is only 0 returning a new 4x4x4 array with only 1s in it.
I can do this for a 2 dimensional array with
a = np.delete(a,np.where(~a.any(axis=0))[0], axis=1)
a = a[~np.all(a == 0, axis=1)]
But can't figure how to do it with 3 dimensions
Anyone have an idea how that can be done?
a[3, 1, 3] = 0a[:,3,:] = 0anda[:,:,3]=0(5,4,4)for your example.