I have a numpy array which looks like: [3,65,7,83,2,4]
and I want to keep indices [1,3,5]
. Which would give me [65, 83, 4]
. Is there a way to do this in Numpy?
This would essentially be the opposite of the numpy.delete
function.
Use fancy indexing:
>>> a = np.array([3,65,7,83,2,4])
>>> a[[1, 3, 5]]
array([65, 83, 4])
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