performance - Is there a better way of getting elements with x,y coordinates from a numpy array? -


it possible index numpy array tuple of sequences such tpl[0] a sequence of x coordinates , tple[1] sequence of y coordinates. 1 needs index array tuple, thus: other_array[tpl].

i have coordinates stored in 2d array such vector ar[0] corresponds x values , ar[1] corresponds y values.

right now, i'm indexing other_array creating tuple: other_array((ar[0], ar[1])). unfortunately, operation running in tight loop, amount of performance can squeeze out highly beneficial. creating tuple can add bit of overhead if performed 10^8 times! there faster, numpythonic way of indexing such matrix of xy coordinates?

thank much!

you can index numpy array array, don't have create tuple. example:

in [199]: other_array out[199]:  array([[ 0,  1,  2,  3,  4],        [ 5,  6,  7,  8,  9],        [10, 11, 12, 13, 14]])  in [200]: ar out[200]:  array([[0, 2, 1],        [1, 3, 0]])  in [201]: other_array[ar[0], ar[1]] out[201]: array([ 1, 13,  5]) 

if doesn't answer question, include simple working example in question shows doing?


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -