Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #109029 > unrolled thread
| Started by | Michael Selik <michael.selik@gmail.com> |
|---|---|
| First post | 2016-05-23 23:00 +0000 |
| Last post | 2016-05-23 23:00 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: numpy problem Michael Selik <michael.selik@gmail.com> - 2016-05-23 23:00 +0000
| From | Michael Selik <michael.selik@gmail.com> |
|---|---|
| Date | 2016-05-23 23:00 +0000 |
| Subject | Re: numpy problem |
| Message-ID | <mailman.37.1464044443.20402.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web