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? Thanks, Josef
On Wed, 20130206 at 13:08 0500, josef.pktd@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]) Regards, Sebastian
Thanks,
Josef _______________________________________________ NumPyDiscussion mailing list NumPyDiscussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpydiscussion
On Wed, Feb 6, 2013 at 2:17 PM, Sebastian Berg <sebastian@sipsolutions.net> wrote:
On Wed, 20130206 at 13:08 0500, josef.pktd@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 _______________________________________________ NumPyDiscussion mailing list NumPyDiscussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpydiscussion
_______________________________________________ NumPyDiscussion mailing list NumPyDiscussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpydiscussion
On Wed, Feb 6, 2013 at 1:08 PM, <josef.pktd@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?
Some possibilities: np.array_split() np.split() np.ndindex() np.nditer() np.nested_iters() np.ravel_multi_index() Your description reminded me of a function I came across once, but I can't remember if one of these was it or if it was another one. IHTH, Ben Root
On Wed, Feb 6, 2013 at 2:45 PM, Benjamin Root <ben.root@ou.edu> wrote:
On Wed, Feb 6, 2013 at 1:08 PM, <josef.pktd@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?
Some possibilities:
np.array_split() np.split()
perfect (haven't gotten further down the list yet)
np.split(np.arange(15), [3,4,6, 13]) [array([0, 1, 2]), array([3]), array([4, 5]), array([ 6, 7, 8, 9, 10, 11, 12]), array([13, 14])]
docstring says equal size, which fortunately is not correct http://docs.scipy.org/doc/numpy/reference/generated/numpy.split.html Thank you, Josef
np.ndindex() np.nditer() np.nested_iters() np.ravel_multi_index()
Your description reminded me of a function I came across once, but I can't remember if one of these was it or if it was another one.
IHTH, Ben Root
_______________________________________________ NumPyDiscussion mailing list NumPyDiscussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpydiscussion
participants (3)

Benjamin Root

josef.pktd＠gmail.com

Sebastian Berg