I have a NumPy array like:
a = np.array([1,2,3,4,0,0,5,6,7,8,0,0,9,10,11,12])
What is the most effective way to select all values except values (in my example is 0) at some positions?
So I need to get an array:
[1,2,3,4,5,6,7,8,9,10,11,12]
I know how to skip the one nth value with [::n]
construction but is it possible to skip several values using the similar syntax?
Thank you for any help!
You probably want np.delete
:
>>> np.delete(a, [4, 5, 10, 11])
array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
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