On Mon, May 23, 2016 at 9:12 AM <li...@onemanifest.net> wrote:

> > On 23 mei 2016, at 14:19, Peter Otten <__pete...@web.de> wrote:
> > li...@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.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to