numpy.histogramdd#

numpy.histogramdd(sample,bins=10,range=None,density=None,weights=None)[source]#

Compute the multidimensional histogram of some data.

Parameters:
sample(N, D) array, or (N, D) array_like

The data to be histogrammed.

Note the unusual interpretation of sample when an array_like:

  • When an array, each row is a coordinate in a D-dimensional space -such ashistogramdd(np.array([p1,p2,p3])).

  • When an array_like, each element is the list of values for singlecoordinate - such ashistogramdd((X,Y,Z)).

The first form should be preferred.

binssequence or int, optional

The bin specification:

  • A sequence of arrays describing the monotonically increasing binedges along each dimension.

  • The number of bins for each dimension (nx, ny, … =bins)

  • The number of bins for all dimensions (nx=ny=…=bins).

rangesequence, optional

A sequence of length D, each an optional (lower, upper) tuple givingthe outer bin edges to be used if the edges are not given explicitly inbins.An entry of None in the sequence results in the minimum and maximumvalues being used for the corresponding dimension.The default, None, is equivalent to passing a tuple of D None values.

densitybool, optional

If False, the default, returns the number of samples in each bin.If True, returns the probabilitydensity function at the bin,bin_count/sample_count/bin_volume.

weights(N,) array_like, optional

An array of valuesw_i weighing each sample(x_i, y_i, z_i, …).Weights are normalized to 1 if density is True. If density is False,the values of the returned histogram are equal to the sum of theweights belonging to the samples falling into each bin.

Returns:
Hndarray

The multidimensional histogram of sample x. See density and weightsfor the different possible semantics.

edgestuple of ndarrays

A tuple of D arrays describing the bin edges for each dimension.

See also

histogram

1-D histogram

histogram2d

2-D histogram

Examples

>>>importnumpyasnp>>>rng=np.random.default_rng()>>>r=rng.normal(size=(100,3))>>>H,edges=np.histogramdd(r,bins=(5,8,4))>>>H.shape,edges[0].size,edges[1].size,edges[2].size((5, 8, 4), 6, 9, 5)
On this page