Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #108994
| From | lists@onemanifest.net |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: numpy problem |
| Date | 2016-05-23 15:10 +0200 |
| Message-ID | <mailman.19.1464009073.20402.python-list@python.org> (permalink) |
| References | <46F1751E-CA1E-4AB3-B6EB-589E1E2FD1D9@onemanifest.net> <nhusgg$vna$1@ger.gmane.org> <17D9C96A-C4EB-426F-A4A7-AA6492D7DBAB@onemanifest.net> |
[Multipart message — attachments visible in raw view] - view raw
> > On 23 mei 2016, at 14:19, Peter Otten <__peter__@web.de> wrote: > > lists@onemanifest.net wrote: > >> 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? > > How about > > values[keep].diagonal() That seems to do the trick! Thx.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: numpy problem lists@onemanifest.net - 2016-05-23 15:10 +0200
csiph-web