[Numpy-discussion] Incrementing with advanced indexing: why don't repeated indexes repeatedly increment?
Wed Jun 6 09:45:58 CDT 2012
Thank you for the suggestion, but it looks like that has the same behavior
In : x = zeros(5)
In : idx = array([1,1,1,3,4])
In : put(x,idx, [2,4,8,10,30])
In : x
Out: array([ 0., 8., 0., 10., 30.])
On Wed, Jun 6, 2012 at 6:07 AM, Frédéric Bastien <email@example.com> wrote:
> I get across the numpy.put function. I'm not sure, but maybe it do
> what you want. My memory are fuzy about this and they don't tell about
> this in the doc of this function.
>  http://docs.scipy.org/doc/numpy/reference/generated/numpy.put.html
> On Wed, Jun 6, 2012 at 4:48 AM, John Salvatier
> <firstname.lastname@example.org> wrote:
> > Hello,
> > I've noticed that If you try to increment elements of an array with
> > indexing, repeated indexes don't get repeatedly incremented. For example:
> > In : x = zeros(5)
> > In : idx = array([1,1,1,3,4])
> > In : x[idx] += [2,4,8,10,30]
> > In : x
> > Out: array([ 0., 8., 0., 10., 30.])
> > I would intuitively expect the output to be array([0,14, 0,10,30]) since
> > index 1 is incremented by 2+4+8=14, but instead it seems to only
> > by 8. What is numpy actually doing here?
> > The authors of Theano noticed this behavior a while ago so they python
> > through the values in idx (this kind of calculation is necessary for
> > calculating gradients), but this is a bit slow for my purposes, so I'd
> > to figure out how to get the behavior I expected, but faster.
> > I'm also not sure how to navigate the numpy codebase, where would I look
> > the code responsible for this behavior?
> > _______________________________________________
> > NumPy-Discussion mailing list
> > NumPy-Discussion@scipy.org
> > http://mail.scipy.org/mailman/listinfo/numpy-discussion
> NumPy-Discussion mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion