2021年3月4日星期四

Searching in numpy array

I have a 2D numpy array, say A sorted with respect to Column 0. e.g.

Col.0 Col.1 Col.2
10 2.45 3.25
11 2.95 4
12 3.45 4.25
15 3.95 5
18 4.45 5.25
21 4.95 6
23 5.45 6.25
27 5.95 7
29 6.45 7.25
32 6.95 8
35 7.45 8.25

The entries in each row is unique i.e. Col. 0 is the identification number of a co-ordinate in xy plane, Columns 1 and 2 are x and y co-ordinates of these points. I have another array B (rows can contain duplicate data). Column 0 and Column 1 store x and y co-ordinates.

Col.0 Col.1
2.45 3.25
4.45 5.25
6.45 7.25
2.45 3.25

My aim is to find the row index number in array A corresponding to data in array B without using for loop. So, in this case, my output should be [0,4,8,0]. Now, I know that with numpy searchsorted lookup for multiple data can be done in one shot. But, it can be used to compare with a single column of A and not multiple columns. Is there a way to do this?

https://stackoverflow.com/questions/66483538/searching-in-numpy-array March 05, 2021 at 05:47AM

没有评论:

发表评论