cupy.histogram(x, bins=10, range=None, weights=None, density=False)[source]#

Computes the histogram of a set of data.

  • x (cupy.ndarray) – Input array.

  • bins (int or cupy.ndarray) – If bins is an int, it represents the number of bins. If bins is an ndarray, it represents a bin edges.

  • range (2-tuple of float, optional) – The lower and upper range of the bins. If not provided, range is simply (x.min(), x.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.

  • density (bool, optional) – If False, the default, returns the number of samples in each bin. If True, returns the probability density function at the bin, bin_count / sample_count / bin_volume.

  • weights (cupy.ndarray, optional) – An array of weights, of the same shape as x. Each value in x only contributes its associated weight towards the bin count (instead of 1).


(hist, bin_edges) where hist is a cupy.ndarray storing the values of the histogram, and bin_edges is a cupy.ndarray storing the bin edges.

Return type:



This function may synchronize the device.