[Numpy-discussion] Smart way to do this?

Jose Amoreira ljmamoreira@gmail....
Sat Feb 23 10:51:24 CST 2013


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.,  1.,
>         1.,  1.,  1.,  1.])
> 


Hi!
OK, but is there any reason why Santhu's first option doesn't work? Shouldn't 
it work? 
Cheers,
Ze
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20130223/37291bc4/attachment.html 


More information about the NumPy-Discussion mailing list