[Numpy-discussion] Fast histogram

Zachary Pincus zachary.pincus@yale....
Thu Apr 17 11:54:18 CDT 2008


Hi, and thanks for the suggestion!

> How many bits per pixel does your camera actually generate !?
> If its for example a 12 bit camera, you could just fill in directly
> into 4096 preallocated bins.
> You would not need any sorting !!
> That's what I did for a 16 bit camera -- but I wrote it in C and I had
> 4 cameras at 30 Hz.

That approach avoids the bin-index calculation line:
indices = numpy.clip(((array.astype(float) - min) * bins / (max -  
min)).astype(int), 0, bins-1)

But even if indices = array, one still needs to do something like:
for index in indices: histogram[index] += 1

Which is slow in python and fast in C.

I'm guessing that there's no utility function in numpy that does a  
loop like this? If so, that would be handy, but if now, I think I need  
to dig out the numpy book and write a little extension...

Zach


More information about the Numpy-discussion mailing list