Re: [Numpy-discussion] Smart way to do this?

2013-02-23 Thread Jose Amoreira
On Saturday, February 23, 2013 00:45:55 Brett Olsen wrote: a = np.ones(30) idx = np.array([2, 3, 2]) a += 2 * np.bincount(idx, minlength=len(a)) a array([ 1., 1., 5., 3., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,

Re: [Numpy-discussion] Smart way to do this?

2013-02-23 Thread Nathaniel Smith
On Sat, Feb 23, 2013 at 4:51 PM, Jose Amoreira ljmamore...@gmail.com wrote: On Saturday, February 23, 2013 00:45:55 Brett Olsen wrote: a = np.ones(30) idx = np.array([2, 3, 2]) a += 2 * np.bincount(idx, minlength=len(a)) a array([ 1., 1., 5., 3., 1., 1., 1., 1., 1., 1., 1., 1., 1.,

[Numpy-discussion] Smart way to do this?

2013-02-22 Thread santhu kumar
Hi all, I dont want to run a loop for this but it should be possible using numpy smart ways. a = np.ones(30) idx = np.array([2,3,2]) # there is a duplicate index of 2 a += 2 a array([ 1., 1., 3., 3., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,

Re: [Numpy-discussion] Smart way to do this?

2013-02-22 Thread santhu kumar
Sorry typo : a = np.ones(30) idx = np.array([2,3,2]) # there is a duplicate index of 2 a[idx] += 2 On Fri, Feb 22, 2013 at 8:35 PM, santhu kumar mesan...@gmail.com wrote: Hi all, I dont want to run a loop for this but it should be possible using numpy smart ways. a = np.ones(30) idx =

Re: [Numpy-discussion] Smart way to do this?

2013-02-22 Thread Brett Olsen
a = np.ones(30) idx = np.array([2, 3, 2]) a += 2 * np.bincount(idx, minlength=len(a)) a array([ 1., 1., 5., 3., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]) As for speed: def loop(a, idx):