[Numpy-discussion] np.histogram on arrays.

eat e.antero.tammi@gmail....
Thu Mar 31 04:28:12 CDT 2011


On Wed, Mar 30, 2011 at 1:44 PM, Éric Depagne <eric@depagne.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
> know
> > how the counts and bounds are used later on. Just wondering if this kind
> > massive histogramming could be somehow avoided totally.
> Indeed.
> Here's what I do.
> My images come from CCD, and as such, the zero level in the image is not
> the
> true zero level, but is the true zero + the background noise of each
> pixels.
> By doing the histogram, I plan on detecting what is the most common value
> per
> row.
> Once I have the most common value, I can derive the interval where most of
> the
> values are (the index of the largest occurence is easily obtained by
> sorting
> 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
> of
> 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
> of
> 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[0], a.shape[0])[:, 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).


> Éric.
> >
> > Regards,
> > eat
> >
> Un clavier azerty en vaut deux
> ----------------------------------------------------------
> Éric Depagne                            eric@depagne.org
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110331/cca1dbc0/attachment.html 

More information about the NumPy-Discussion mailing list