pyyeti.ytools.histogram¶
- pyyeti.ytools.histogram(data, binsize)[source]¶
Calculate a histogram
- Parameters:
data (1d array_like) – The data to do histogram counting on
binsize (scalar) – Bin size
- Returns:
histo (2d ndarray) – 3-column matrix: [bincenter, count, percent]
Notes
Only bins that have count > 0 are included in the output. The bin-centers are:
binsize*[..., -2, -1, 0, 1, 2, ...].The main difference from
numpy.histogram()is how bins are defined and how the data are returned. Fornumpy.histogram(), you must either define the number of bins or the bin edges and the output will include empty bins; for this routine, you only define the binsize and only non-empty bins are returned.Examples
>>> import numpy as np >>> np.set_printoptions(precision=4, suppress=True) >>> from pyyeti import ytools >>> data = [1, 2, 345, 2.4, 1.8, 345.1] >>> ytools.histogram(data, 1.0) array([[ 1. , 1. , 16.6667], [ 2. , 3. , 50. ], [ 345. , 2. , 33.3333]])
To try to get similar output from
numpy.histogram()you have to define the bins:>>> binedges = [0.5, 1.5, 2.5, 344.5, 345.5] >>> cnt, bins = np.histogram(data, binedges) >>> cnt array([1, 3, 0, 2]...) >>> bins array([ 0.5, 1.5, 2.5, 344.5, 345.5])