I have a numpy ndarray that looks like:
[[  0   0   0],
[  0   0   0],
[  0   0   0],
[  0   0   0],
[  0   0   0],
[  0   0   0],
[  0   0   0],
[225 224 228],
[163 164 174],
[205 212 229],
[116 130 153],
[ 81 101 132],
[ 34  56  92],
[  2  16  35],
[ 33  44  64],
[ 38  49  71],
[ 63  75  99],
[ 76  88 116],
[ 45  62  95],
[ 29  50  88],
[ 18  40  82],
[  0   0   0],
[  0   0   0],
[  0   0   0],
[  0   0   0],
[  0   0   0],
[  0   0   0],
[  0   0   0]]
I want to delete all the zero elements i.e. [0,0,0]. How can I do this?
You can use np.delete() and np.where() to get the elements where the condition is satisfied as :
del_arr = np.delete(arr, np.where(arr == [0, 0, 0]), axis=0)
print del_arr
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With