[Numpy-discussion] Array accumulation in numpy

2013-02-19 Thread Tony Ladd
I want to accumulate elements of a vector (x) to an array (f) based on an index list (ind). For example: x=[1,2,3,4,5,6] ind=[1,3,9,3,4,1] f=np.zeros(10) What I want would be produced by the loop for i=range(6): f[ind[i]]=f[ind[i]]+x[i] The answer is f=array([ 0., 7., 0., 6., 5.,

Re: [Numpy-discussion] Array accumulation in numpy

2013-02-19 Thread Benjamin Root
On Tue, Feb 19, 2013 at 10:00 AM, Tony Ladd tl...@che.ufl.edu wrote: I want to accumulate elements of a vector (x) to an array (f) based on an index list (ind). For example: x=[1,2,3,4,5,6] ind=[1,3,9,3,4,1] f=np.zeros(10) What I want would be produced by the loop for i=range(6):

Re: [Numpy-discussion] Array accumulation in numpy

2013-02-19 Thread Sebastian Berg
On Tue, 2013-02-19 at 10:00 -0500, Tony Ladd wrote: I want to accumulate elements of a vector (x) to an array (f) based on an index list (ind). For example: x=[1,2,3,4,5,6] ind=[1,3,9,3,4,1] f=np.zeros(10) What I want would be produced by the loop for i=range(6):

Re: [Numpy-discussion] Array accumulation in numpy

2013-02-19 Thread Alan G Isaac
x=[1,2,3,4,5,6] ind=[1,3,9,3,4,1] f=np.zeros(10) np.bincount(ind,x) hth, Alan Isaac ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

Re: [Numpy-discussion] Array accumulation in numpy

2013-02-19 Thread Tony Ladd
Alan Thanks - I felt sure there had to be an easy idea. Best Tony On 02/19/2013 10:17 AM, Alan G Isaac wrote: x=[1,2,3,4,5,6] ind=[1,3,9,3,4,1] f=np.zeros(10) np.bincount(ind,x) hth, Alan Isaac ___ NumPy-Discussion mailing list

Re: [Numpy-discussion] Array accumulation in numpy

2013-02-19 Thread Tony Ladd
Thanks to all for a very quick response. np.bincount does what I need. Tony On 02/19/2013 10:04 AM, Benjamin Root wrote: On Tue, Feb 19, 2013 at 10:00 AM, Tony Ladd tl...@che.ufl.edu mailto:tl...@che.ufl.edu wrote: I want to accumulate elements of a vector (x) to an array (f) based on

Re: [Numpy-discussion] Array accumulation in numpy

2013-02-19 Thread Eraldo Pomponi
Dear Tony, I would suggest to look at this post already mentioned by Benjamin . maybe it fits with your needs! http://numpy-discussion.10968.n7.nabble.com/Pre-allocate-array-td4870.html Cheers, Eraldo On Tue, Feb 19, 2013 at 4:24 PM, Tony Ladd tl...@che.ufl.edu wrote: Thanks to all for