Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #109029
| From | Michael Selik <michael.selik@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: numpy problem |
| Date | 2016-05-23 23:00 +0000 |
| Message-ID | <mailman.37.1464044443.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> <CAGgTfkPR2FMuKW6j5DrowYT5ML4prG8z1=8qhhviW4Z-K8WkoQ@mail.gmail.com> |
On Mon, May 23, 2016 at 9:12 AM <lists@onemanifest.net> wrote: > > On 23 mei 2016, at 14:19, Peter Otten <__peter__@web.de> wrote: > > lists@onemanifest.net wrote: > > > >> I've got a 2D array > >> 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]) > >> > > values[keep].diagonal() > > That seems to do the trick! > To clarify, the fancy index is selecting all rows you want to keep, which gives you a 5x5 array (repeating rows if necessary). Then you are getting the diagonal of that selection. If that was already clear, my apologies for the noise.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: numpy problem Michael Selik <michael.selik@gmail.com> - 2016-05-23 23:00 +0000
csiph-web