[Numpy-discussion] nonuniform scatter operations

Anne Archibald peridot.faceted@gmail....
Sun Sep 28 01:50:10 CDT 2008


2008/9/28 Geoffrey Irving <irving@naml.us>:

> Is there an efficient way to implement a nonuniform gather operation
> in numpy?  Specifically, I want to do something like
>
> n,m = 100,1000
> X = random.uniform(size=n)
> K = random.randint(n, size=m)
> Y = random.uniform(size=m)
>
> for k,y in zip(K,Y):
>    X[k] += y
>
> but I want it to be fast.  The naive attempt "X[K] += Y" does not
> work, since the slice assumes the indices don't repeat.

I believe histogram can be persuaded to do this.

Anne


More information about the Numpy-discussion mailing list