scipy.ndimage.
histogram#
- scipy.ndimage.histogram(input,min,max,bins,labels=None,index=None)[source]#
Calculate the histogram of the values of an array, optionally at labels.
Histogram calculates the frequency of values in an array within binsdetermined bymin,max, andbins. Thelabels andindexkeywords can limit the scope of the histogram to specified sub-regionswithin the array.
- Parameters:
- inputarray_like
Data for which to calculate histogram.
- min, maxint
Minimum and maximum values of range of histogram bins.
- binsint
Number of bins.
- labelsarray_like, optional
Labels for objects ininput.If not None, must be same shape asinput.
- indexint or sequence of ints, optional
Label or labels for which to calculate histogram. If None, all valueswhere label is greater than zero are used
- Returns:
- histndarray
Histogram counts.
Examples
>>>importnumpyasnp>>>a=np.array([[0.,0.2146,0.5962,0.],...[0.,0.7778,0.,0.],...[0.,0.,0.,0.],...[0.,0.,0.7181,0.2787],...[0.,0.,0.6573,0.3094]])>>>fromscipyimportndimage>>>ndimage.histogram(a,0,1,10)array([13, 0, 2, 1, 0, 1, 1, 2, 0, 0])
With labels and no indices, non-zero elements are counted:
>>>lbl,nlbl=ndimage.label(a)>>>ndimage.histogram(a,0,1,10,lbl)array([0, 0, 2, 1, 0, 1, 1, 2, 0, 0])
Indices can be used to count only certain objects:
>>>ndimage.histogram(a,0,1,10,lbl,2)array([0, 0, 1, 1, 0, 0, 1, 1, 0, 0])
On this page