I am having trouble trying to obtain a boolean array that indicates when an element in the second numpy array is also in the first array.
The challenging part is that each array is made up of Latitude/Longitude pairs and I want to make sure that each Lat/Lon in secondcoords is also in firstcoords. So, this is like an intersection
Here is what I have done thus far (with small example coordinates):
firstlat = [0, 1, 5, 5]
firstlon = [1, 0, 5, 4]
secondlat = [0, 2, 0, 5]
secondlon = [1, 2, 5, 5]
firstcoords = numpy.array((firstlat, firstlon))
firstcoords = numpy.transpose(firstcoords) # gets lat/lon pair
secondcoords = numpy.array((secondlat, secondlon))
secondcoords = numpy.transpose(secondcoords)
a = numpy.isin(secondcoords, firstcoords)
Wrong output:
[[ True True]
[False False]
[ True True]
[ True True]]
Wanted output: [[True, False, False, True]]
Numpy isin flattens the arguments so although firstcoords[0] = [0 1]
, it seems to be improperly comparing it "element by element". However, as I saw, each element comprises of both the [lat lon]
; and the purpose to transpose it was to get the lat / lons
in tuple or tuple-like form for easier comparison. So, how do I fix my approach or what other approaches would be feasible for this problem?