Referring to this previous question:
Remove all-zero rows in a 2D matrix
import numpy as np
data = np.array([[4, 1, 1, 2, 0, 4],
[3, 4, 3, 1, 4, 4],
[1, 4, 3, 1, 0, 0],
[0, 4, 4, 0, 4, 3],
[0, 0, 0, 0, 0, 0]])
data = data[~(data==0).all(1)]
print(data)
Output :
[[4 1 1 2 0 4]
[3 4 3 1 4 4]
[1 4 3 1 0 0]
[0 4 4 0 4 3]]
ok so far so good but what if i add null column?
data = np.array([[0, 4, 1, 1, 2, 0, 4],
[0, 3, 4, 3, 1, 4, 4],
[0, 0, 1, 4, 3, 1, 0],
[0, 0, 4, 4, 0, 4, 3],
[0, 0, 0, 0, 0, 0, 0]])
Output is
[[0 4 1 1 2 0 4]
[0 3 4 3 1 4 4]
[0 1 4 3 1 0 0]
[0 0 4 4 0 4 3]]
which is not what i want.
Basically if my matrix is :
[[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 4, 1, 1, 2, 0, 4, 0],
[0, 0, 3, 4, 3, 1, 4, 4, 0],
[0, 0, 1, 4, 3, 1, 0, 0, 0],
[0, 0, 0, 4, 4, 0, 4, 3, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0]]
The output i'll be expecting is
[[4 1 1 2 0 4]
[3 4 3 1 4 4]
[1 4 3 1 0 0]
[0 4 4 0 4 3]]