numpy problem

lists at onemanifest.net lists at onemanifest.net
Sun May 22 15:42:25 EDT 2016


Hi,

I've got a nympy problem I can't get my head around. (numpy is new to me).

I've got a 2D array with values:

values = np.array(
[[ 20, 38,  4,  45, 65],
 [ 81, 44, 38,  57, 92],
 [ 92, 41, 16,  77, 44],
 [ 53, 62,  9,  75, 12],
 [ 58,  2, 60, 100, 29],
 [ 63, 15, 48,  43, 71],
 [ 80, 97, 87,  64, 60],
 [ 16, 16, 70,  88, 80],
 [ 19,  1, 73,  39, 97],
 [ 48,  3, 27,  81, 14]])

And an array of indexes that for shows which row to keep for each column of values:

keep = np.array([2, 3, 1, 9, 2])

So, the result should be an array like array([ values[2,0], values[3,1], values[1,2], values[9,3], values[2,4] ]) == np.array([92, 62, 38, 81, 44])

Can this be accomplished in a vectorized manner?


Thx,

Peter
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 842 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://mail.python.org/pipermail/python-list/attachments/20160522/018fc447/attachment.sig>


More information about the Python-list mailing list