bundles / scipy latest / scipy / ndimage / _measurements / histogram
function
scipy.ndimage._measurements:histogram
Signature
def histogram ( input , min , max , bins , labels = None , index = None ) Summary
Calculate the histogram of the values of an array, optionally at labels.
Extended Summary
Histogram calculates the frequency of values in an array within bins determined by min, max, and bins. The labels and index keywords can limit the scope of the histogram to specified sub-regions within the array.
Parameters
input: array_likeData for which to calculate histogram.
min, max: intMinimum and maximum values of range of histogram bins.
bins: intNumber of bins.
labels: array_like, optionalLabels for objects in
input. If not None, must be same shape asinput.index: int or sequence of ints, optionalLabel or labels for which to calculate histogram. If None, all values where label is greater than zero are used
Returns
hist: ndarrayHistogram counts.
Notes
Array API Standard Support
histogram has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ✅ PyTorch ✅ ⛔ JAX ⚠️ no JIT ⛔ Dask ⚠️ computes graph n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
import numpy as np 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]]) from scipy import ndimage ndimage.histogram(a, 0, 1, 10)✓
lbl, nlbl = ndimage.label(a) ndimage.histogram(a, 0, 1, 10, lbl)✓
ndimage.histogram(a, 0, 1, 10, lbl, 2)
✓Aliases
-
scipy.ndimage.histogram