dpnp.histogram2d
- dpnp.histogram2d(x, y, bins=10, range=None, density=None, weights=None)[source]
Compute the bi-dimensional histogram of two data samples.
For full documentation refer to
numpy.histogram2d.Warning
This function may synchronize in order to check a monotonically increasing array of bin edges. This may harm performance in some applications.
- Parameters:
x ({dpnp.ndarray, usm_ndarray} of shape (N,)) -- An array containing the x coordinates of the points to be histogrammed.
y ({dpnp.ndarray, usm_ndarray} of shape (N,)) -- An array containing the y coordinates of the points to be histogrammed.
bins ({int, dpnp.ndarray, usm_ndarray, [int, int], [array, array], [int, array], [array, int]}, optional) --
The bins specification:
If int, the number of bins for the two dimensions (nx=ny=bins).
If array, the bin edges for the two dimensions (x_edges=y_edges=bins).
If [int, int], the number of bins in each dimension (nx, ny = bins).
If [array, array], the bin edges in each dimension (x_edges, y_edges = bins).
A combination [int, array] or [array, int], where int is the number of bins and array is the bin edges.
Default:
10.range ({None, dpnp.ndarray, usm_ndarray} of shape (2, 2), optional) --
The leftmost and rightmost edges of the bins along each dimension If
Nonethe ranges are[[x.min(), x.max()], [y.min(), y.max()]]. All values outside of this range will be considered outliers and not tallied in the histogram.Default:
None.density ({None, bool}, optional) --
If
FalseorNone, the default, returns the number of samples in each bin. IfTrue, returns the probability density function at the bin,bin_count / sample_count / bin_volume.Default:
None.weights ({None, dpnp.ndarray, usm_ndarray} of shape (N,), optional) --
An array of values
w_iweighing each sample(x_i, y_i). Weights are normalized to1if density isTrue. If density isFalse, the values of the returned histogram are equal to the sum of the weights belonging to the samples falling into each bin. IfNoneall samples are assigned a weight of1.Default:
None.
- Returns:
H (dpnp.ndarray of shape (nx, ny)) -- The bi-dimensional histogram of samples x and y. Values in x are histogrammed along the first dimension and values in y are histogrammed along the second dimension.
xedges (dpnp.ndarray of shape (nx+1,)) -- The bin edges along the first dimension.
yedges (dpnp.ndarray of shape (ny+1,)) -- The bin edges along the second dimension.
See also
dpnp.histogram1D histogram
dpnp.histogramddMultidimensional histogram
Notes
When density is
True, then the returned histogram is the sample density, defined such that the sum over bins of the productbin_value * bin_areais 1.Please note that the histogram does not follow the Cartesian convention where x values are on the abscissa and y values on the ordinate axis. Rather, x is histogrammed along the first dimension of the array (vertical), and y along the second dimension of the array (horizontal). This ensures compatibility with histogramdd.
Examples
>>> import dpnp as np >>> x = np.random.randn(20).astype("float32") >>> y = np.random.randn(20).astype("float32") >>> hist, edges_x, edges_y = np.histogram2d(x, y, bins=(4, 3)) >>> hist.shape (4, 3) >>> hist array([[1., 2., 0.], [0., 3., 1.], [1., 4., 1.], [1., 3., 3.]], dtype=float32) >>> edges_x.shape (5,) >>> edges_x array([-1.7516936 , -0.96109843, -0.17050326, 0.62009203, 1.4106871 ], dtype=float32) >>> edges_y.shape (4,) >>> edges_y array([-2.6604428 , -0.94615364, 0.76813555, 2.4824247 ], dtype=float32)
Please note, that resulting values of histogram and edges may vary.