Reputation: 6768
I've got a big numpy array full of coordinates (about 400):
[[102, 234],
[304, 104],
....
]
And a numpy 2d array my_map of size 800x800.
What's the fastest way to look up the coordinates given in that array? I tried things like paletting as described in this post: http://opencvpython.blogspot.com/2012/06/fast-array-manipulation-in-numpy.html but couldn't get it to work.
I was also thinking about turning each coordinate into a linear index of the map and then piping it straight into my_map like so:
my_map[linearized_coords]
but I couldn't get vectorize to properly translate the coordinates into a linear fashion. Any ideas?
Upvotes: 1
Views: 407
Reputation: 179402
Try using a tuple
for indexing:
my_map[tuple(coords.T)]
This selects elements of the array via advanced indexing.
Upvotes: 2