Here is my code to delete given row numbers
a = np.arange(12).reshape(6, 2)
b = [1, 4]
a: [[ 0 1]
[ 2 3]
[ 4 5]
[ 6 7]
[ 8 9]
[10 11]]
then i delete the lines in b :
np.delete(a, b, 0)
output :
array([[ 0, 1],
[ 4, 5],
[ 6, 7],
[10, 11]])
I want to use this logic to only keep the rows in b, and do the reverse operation without any loop.
so expected output will be :
output: [
[ 2, 3]
[ 8, 9]
]
np.deleteinternally figures out which rows you want to keep, and returns those. So keeping the thebrows is actually simpler - conceptually and computationally.