简体   繁体   中英

How do I count the number of matching rows between two arrays?

I have two 2D arrays of differing sizes containing coordinates. I am trying to take the first array (which is shorter) and see if any of the coordinates contained in there appear in the second larger array. Thereby taking each row and checking to see if it matches a row in the other array. Both arrays are Numpy arrays.

Is there anyway to compute the number of matching rows? I have been racking my brain about this all day and scouring the web but can't seem to find what I am looking for!

The smaller query array has 2 columns and roughly 100 rows of coordinate points whilst the larger has around 350 coordinate points.

Can be done by using tuples instead of Numpy arrays like so:

data1 = set(tuple(pair) for pair in array1)

data2 = set(tuple(pair) for pair in array2)

matches = data1 & data2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM