nlcpy.histogram
- nlcpy.histogram(a, bins=10, range=None, weights=None, density=None)
Computes the histogram of a set of data.
- Parameters
- aarray_like
Input data. The histogram is computed over the flattened array.
- binsint or sequence of scalars or str, optional
If bins is an int, it defines the number of equal-width bins in the given range (10, by default). If bins is a sequence, it defines a monotonically increasing array of bin edges, including the rightmost edge, allowing for non-uniform bin widths. If bins is a string, it defines the method used to calculate the optimal bin width, as defined by
histogram_bin_edges()
.- range(float, float), optional
The lower and upper range of the bins. If not provided, range is simply
(a.min(), a.max()).
Values outside the range are ignored. The first element of the range must be less than or equal to the second. range affects the automatic bin computation as well. While bin width is computed to be optimal based on the actual data within range, the bin count will fill the entire range including portions containing no data.- weightsarray_like, optional
An array of weights, of the same shape as a. Each value in a only contributes its associated weight towards the bin count (instead of 1). If density is True, the weights are normalized, so that the integral of the density over the range remains 1.
- densitybool, optional
If
False
, the result will contain the number of samples in each bin. IfTrue
, the result is the value of the probability density function at the bin, normalized such that the integral over the range is 1. Note that the sum of the histogram values will not be equal to 1 unless bins of unity width are chosen; it is not a probability mass function.
- Returns
- histndarray
The values of the histogram. See density and weights for a description of the possible semantics.
- bin_edgesarray of dtype float
Return the bin edges
(length(hist)+1)
.
参考
histogramdd
Computes the multidimensional histogram of some data.
bincount
Counts number of occurrences of each value in array of non-negative ints.
digitize
Returns the indices of the bins to which each value in input array belongs.
histogram_bin_edges
Function to calculate only the edges of the bins used by the histogram function.
注釈
All but the last (righthand-most) bin is half-open. In other words, if bins is:
[1, 2, 3, 4]
then the first bin is
[1, 2)
(including 1, but excluding 2) and the second[2, 3)
. The last bin, however, is[3, 4]
, which includes 4.制限事項
This function is the wrapper function to utilize
numpy.histogram()
. Calculations during this function perform on only Vector Host(Linux/x86).Examples
>>> import nlcpy as vp >>> vp.histogram([1, 2, 1], bins=[0, 1, 2, 3]) (array([0, 2, 1]), array([0, 1, 2, 3])) >>> vp.histogram(vp.arange(4), bins=vp.arange(5), density=True) (array([0.25, 0.25, 0.25, 0.25]), array([0, 1, 2, 3, 4])) >>> vp.histogram([[1, 2, 1], [1, 0, 1]], bins=[0,1,2,3]) (array([1, 4, 1]), array([0, 1, 2, 3])) >>> a = vp.arange(5) >>> hist, bin_edges = vp.histogram(a, density=True) >>> hist array([0.5, 0. , 0.5, 0. , 0. , 0.5, 0. , 0.5, 0. , 0.5]) >>> vp.sum(hist * vp.diff(bin_edges)) array(1.)