histogramdd

paddle. histogramdd ( x, bins=10, ranges=None, density=False, weights=None, name=None ) [source]

Computes a multi-dimensional histogram of the values in a tensor.

Interprets the elements of an input tensor whose innermost dimension has size N as a collection of N-dimensional points. Maps each of the points into a set of N-dimensional bins and returns the number of points (or total weight) in each bin.

input x must be a tensor with at least 2 dimensions. If input has shape (M, N), each of its M rows defines a point in N-dimensional space. If input has three or more dimensions, all but the last dimension are flattened.

Each dimension is independently associated with its own strictly increasing sequence of bin edges. Bin edges may be specified explicitly by passing a sequence of 1D tensors. Alternatively, bin edges may be constructed automatically by passing a sequence of integers specifying the number of equal-width bins in each dimension.

Parameters
  • x (Tensor) – The input tensor.

  • bins (Tensor[], int[], or int) – If Tensor[], defines the sequences of bin edges. If int[], defines the number of equal-width bins in each dimension. If int, defines the number of equal-width bins for all dimensions.

  • ranges (sequence of float, optional) – Defines the leftmost and rightmost bin edges in each dimension. If is None, set the minimum and maximum as leftmost and rightmost edges for each dimension.

  • density (bool, optional) – If False (default), the result will contain the count (or total weight) in each bin. If True, each count (weight) is divided by the total count (total weight), then divided by the volume of its associated bin.

  • weights (Tensor, optional) – By default, each value in the input has weight 1. If a weight tensor is passed, each N-dimensional coordinate in input contributes its associated weight towards its bin’s result. The weight tensor should have the same shape as the input tensor excluding its innermost dimension N.

  • name (str, optional) – For details, please refer to Name. Generally, no setting is required. Default: None.

Returns

N-dimensional Tensor containing the values of the histogram. bin_edges(Tensor[]), sequence of N 1D Tensors containing the bin edges.

Examples

>>> import paddle
>>> x = paddle.to_tensor([[0., 1.], [1., 0.], [2.,0.], [2., 2.]])
>>> bins = [3,3]
>>> weights = paddle.to_tensor([1., 2., 4., 8.])
>>> paddle.histogramdd(x, bins=bins, weights=weights)
(Tensor(shape=[3, 3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
       [[0., 1., 0.],
        [2., 0., 0.],
        [4., 0., 8.]]), [Tensor(shape=[4], dtype=float32, place=Place(gpu:0), stop_gradient=True,
       [0.        , 0.66666669, 1.33333337, 2.        ]), Tensor(shape=[4], dtype=float32, place=Place(gpu:0), stop_gradient=True,
       [0.        , 0.66666669, 1.33333337, 2.        ])])
>>> import paddle
>>> y = paddle.to_tensor([[0., 0.], [1., 1.], [2., 2.]])
>>> bins = [2,2]
>>> ranges = [0., 1., 0., 1.]
>>> density = True
>>> paddle.histogramdd(y, bins=bins, ranges=ranges, density=density)
(Tensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=True,
       [[2., 0.],
        [0., 2.]]), [Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
       [0.        , 0.50000000, 1.        ]), Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
       [0.        , 0.50000000, 1.        ])])