[SciPy-User] Selecting elements in a numpy array by their indices contained in two arrays

Robert Kern robert.kern at gmail.com
Mon Jun 26 19:47:20 EDT 2017


On Mon, Jun 26, 2017 at 4:40 PM, Éric Depagne <eric at depagne.org> wrote:
>
> Le lundi 26 juin 2017, 04:27:47 SAST Éric Depagne a écrit :
>
> > Hi list.
>
> Hi list,
>
> Some more details on my problem.
>
> I know that I can select the elements individually through a for loop,
and that will provide me with the extraction I need, but I was wondering if
there was a way to do that without a loop.
>
> Repeating 4 times A[X1[i]:X2[i],1] will work fine, but I was looking for
something like
> A[X1:X2, 1]

There isn't one since for each `i`, there will be a different number of
items in the slice, so the result would not be able to be fit into an array
with a uniform shape. The loop is the right way to do this.

--
Robert Kern
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-user/attachments/20170626/9ac6f025/attachment.html>


More information about the SciPy-User mailing list