dpnp.histogram
- dpnp.histogram(a, bins=10, range=None, density=None, weights=None)[source]
Compute the histogram of a data set.
For full documentation refer to
numpy.histogram
.- Parameters:
a ({dpnp.ndarray, usm_ndarray}) -- Input data. The histogram is computed over the flattened array.
bins ({int, dpnp.ndarray, usm_ndarray, sequence of scalars}, optional) -- If bins is an int, it defines the number of equal-width bins in the given range. If bins is a sequence, it defines a monotonically increasing array of bin edges, including the rightmost edge, allowing for non-uniform bin widths. Default:
10
.range ({None, 2-tuple of 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. Default:None
.density ({None, bool}, optional) -- If
False
orNone
, 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 is1
. Note that the sum of the histogram values will not be equal to1
unless bins of unity width are chosen; it is not a probability mass function. Default:None
.weights ({None, dpnp.ndarray, usm_ndarray}, 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 remains1
. Please note that thedtype
of weights will also become thedtype
of the returned accumulator (hist), so it must be large enough to hold accumulated values as well. Default:None
.
- Returns:
hist ({dpnp.ndarray}) -- The values of the histogram. See density and weights for a description of the possible semantics. If weights are given,
hist.dtype
will be taken from weights.bin_edges ({dpnp.ndarray of floating data type}) -- Return the bin edges
(length(hist) + 1)
.
See also
dpnp.histogramdd
Compute the multidimensional histogram.
dpnp.bincount
Count number of occurrences of each value in array of non-negative integers.
dpnp.searchsorted
Find indices where elements should be inserted to maintain order.
dpnp.digitize
Return the indices of the bins to which each value in input array belongs.
dpnp.histogram_bin_edges
Return only the edges of the bins used by the obj:dpnp.histogram function.
Examples
>>> import dpnp as np >>> np.histogram(np.array([1, 2, 1]), bins=[0, 1, 2, 3]) (array([0, 2, 1]), array([0, 1, 2, 3])) >>> np.histogram(np.arange(4), bins=np.arange(5), density=True) (array([0.25, 0.25, 0.25, 0.25]), array([0, 1, 2, 3, 4])) >>> np.histogram(np.array([[1, 2, 1], [1, 0, 1]]), bins=[0, 1, 2, 3]) (array([1, 4, 1]), array([0, 1, 2, 3]))
>>> a = np.arange(5) >>> hist, bin_edges = np.histogram(a, density=True) >>> hist array([0.5, 0. , 0.5, 0. , 0. , 0.5, 0. , 0.5, 0. , 0.5]) >>> hist.sum() array(2.5) >>> np.sum(hist * np.diff(bin_edges)) array(1.)