I have a 2-D numpy array with 100,000+ lines. I need to return a subset of these lines (and I need to perform these operations many thousands of times, so efficiency is important).
An example layout is this:
import numpy as np
a = np.array([[1,5.5],
[2,4.5],
[3,9.0],
[4,8.01]])
b = np.array([2,4])
So ... I want to return an array from a with the rows specified in the first column using b:
c=[[2,4.5],
[4,8.01]]
The difference, of course, is that there are many more lines in both and in b, so I would like to avoid a loop. Also, I played with creating a dictionary and using np.nonzero, but still a little puzzled.
Thanks in advance for any ideas!
EDIT: Note that in this case, b are identifiers, not indexes. Here is a revised example:
import numpy as np
a = np.array([[102,5.5],
[204,4.5],
[343,9.0],
[40,8.01]])
b = np.array([102,343])
And I want to return:
c = [[102,5.5],
[343,9.0]]