dpnp.histogram_bin_edges

dpnp.histogram_bin_edges(a, bins=10, range=None, weights=None)[source]

Function to calculate only the edges of the bins used by the dpnp.histogram function.

For full documentation refer to numpy.histogram_bin_edges.

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 the 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.

  • 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). This is currently not used by any of the bin estimators, but may be in the future. Default: None.

Returns:

bin_edges -- The edges to pass into dpnp.histogram.

Return type:

{dpnp.ndarray of floating data type}

See also

dpnp.histogram

Compute the histogram of a data set.

Examples

>>> import dpnp as np
>>> arr = np.array([0, 0, 0, 1, 2, 3, 3, 4, 5])
>>> np.histogram_bin_edges(arr, bins=2)
array([0. , 2.5, 5. ])

For consistency with histogram, an array of pre-computed bins is passed through unmodified:

>>> np.histogram_bin_edges(arr, [1, 2])
array([1, 2])

This function allows one set of bins to be computed, and reused across multiple histograms:

>>> shared_bins = np.histogram_bin_edges(arr, bins=5)
>>> shared_bins
array([0., 1., 2., 3., 4., 5.])
>>> gid = np.array([0, 1, 1, 0, 1, 1, 0, 1, 1])
>>> hist_0, _ = np.histogram(arr[gid == 0], bins=shared_bins)
>>> hist_1, _ = np.histogram(arr[gid == 1], bins=shared_bins)
>>> hist_0, hist_1
(array([1, 1, 0, 1, 0]), array([2, 0, 1, 1, 2]))

Which gives more easily comparable results than using separate bins for each histogram:

>>> hist_0, bins_0 = np.histogram(arr[gid == 0], bins=3)
>>> hist_1, bins_1 = np.histogram(arr[gid == 1], bins=4)
>>> hist_0, hist_1
(array([1, 1, 1]), array([2, 1, 1, 2]))
>>> bins_0, bins_1
(array([0., 1., 2., 3.]), array([0.  , 1.25, 2.5 , 3.75, 5.  ]))