[Numpy-discussion] Where's that function?

josef.pktd at gmail.com josef.pktd at gmail.com
Wed Feb 6 14:32:29 EST 2013


On Wed, Feb 6, 2013 at 2:17 PM, Sebastian Berg
<sebastian at sipsolutions.net> wrote:
> On Wed, 2013-02-06 at 13:08 -0500, josef.pktd at gmail.com wrote:
>> I'm convinced that I saw a while ago a function that uses a list of
>> interval boundaries to index into an array, either to iterate or to
>> take.
>> I thought that's very useful, but didn't make a note.
>>
>> Now, I have no idea where I saw this (I thought numpy), and I cannot
>> find it anywhere.
>>
>> any clues?
>>
>
> It does not quite sound like what you are looking for, but the only
> thing I can think of in numpy right now that does something in that
> direction is the ufunc.reduceat functionality:
>
> In [1]: a = np.arange(10)
>
> In [2]: a[2:5].sum(), a[5:9].sum(), a[9:].sum()
> Out[2]: (9, 26, 9)
>
> In [3]: np.add.reduceat(a, [2, 5, 9])
> Out[3]: array([ 9, 26,  9])

That's what I remembered seeing, but obviously I didn't remember it correctly.

Not useful for my current case, but I will keep it in mind to clean up
some other code.

I will need a python loop after all to take a list of (unequal length)
slices out of an array.

Thank you,

Josef

>
> Regards,
>
> Sebastian
>
>> Thanks,
>>
>> Josef
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion



More information about the NumPy-Discussion mailing list