[Numpy-discussion] np.histogram on arrays.
Thu Mar 31 04:28:12 CDT 2011
On Wed, Mar 30, 2011 at 1:44 PM, Éric Depagne <firstname.lastname@example.org> wrote:
> > Well I guess, for a slight performance improvement, you could create your
> > own streamlined histogrammer.
> > But, in order to better grasp your situation it would be beneficial to
> > how the counts and bounds are used later on. Just wondering if this kind
> > massive histogramming could be somehow avoided totally.
> Here's what I do.
> My images come from CCD, and as such, the zero level in the image is not
> true zero level, but is the true zero + the background noise of each
> By doing the histogram, I plan on detecting what is the most common value
> Once I have the most common value, I can derive the interval where most of
> values are (the index of the largest occurence is easily obtained by
> the counts, and I take a slice [index_max_count,index_max_count+1] in the
> second array given by the histogram).
> Then, I take the mean value of this interval and I assume it is the value
> the bias for my row.
> I do this procedure both on the row and columns as a sanity check.
> And I know this procedure will not work if on any row/column there is a lot
> signal and very little bias. I'll fix that afterwards ;-)
Perhaps something along these lines will help you:
from numpy import histogram, linspace, r_
def hist2(a, nob):
bins= linspace(a.min(), a.max(), nob+ 1)
d= linspace(0, bins[-1]* a.shape, a.shape)[:, None]
b= (a+ d).ravel()
bbins= (bins[:-1]+ d).ravel()
bbins= r_[bbins, bbins[-1]+ 1]
counts, _= histogram(b, bbins)
return counts.reshape(-1, nob), bins
It has two disadvantages 1) needs more memory and 2) "global" bins
(which although should be quite straightforward to enhance if needed).
> > Regards,
> > eat
> Un clavier azerty en vaut deux
> Éric Depagne email@example.com
> NumPy-Discussion mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion