I have the numpy array:
a = np.array([[ 255,255,255],
[ 255,2,255],
[ 3,123,23],
[ 255,255,255],
[ 0, 255, 3]])
And I want to delete all the elements with [ 255,255,255], the result should be:
[[ 255,2,255],
[ 3,123,23],
[ 0, 255, 3]])
I tried with:
import numpy as np
a = np.array([[ 255,255,255],
[ 255,2,255],
[ 3,123,23],
[ 255,255,255],
[ 0, 255, 3]])
np.delete(a, [255,255,255])
but nothing happens.
You can do this:
np.array([x for x in a if np.any(x != 255)])
which gives:
array([[255, 2, 255],
[ 3, 123, 23],
[ 0, 255, 3]])
Edit: To avoid list comprehensions -
np.delete(a, np.where((a == 255).all(axis=1)), axis=0)
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