[Numpy-discussion] vectorizing histogram-like computation

Rick White rlw at stsci.edu
Mon Jun 20 12:52:23 CDT 2005

On Mon, 20 Jun 2005, Piotr Luszczek wrote:

> There is numarray.numeric.histogram and numarray.mlab.histogram.
> What they do is this (more or less):
> for idx in arr:
>     histogram[idx] += 1
> What I want to do is:
> for idx in arr:
>     result[idx] ^= value
> My question is whether there is a way to do it (the XOR example)
> without using a for loop.

Is value the same for every idx?  That's the way you've written it.
If so, you could simply do this:

result = (mlab.histogram(idx) & 1)*value

I'm guessing that you want value to be an array of the same size as
idx though, in which case this would not work.

More information about the Numpy-discussion mailing list