torch.histogramdd#
- torch.histogramdd(input,bins,*,range=None,weight=None,density=False,out=None)->(Tensor,Tensor[])#
Computes a multi-dimensional histogram of the values in a tensor.
Interprets the elements of an input tensor whose innermost dimension has size Nas a collection of N-dimensional points. Maps each of the points into a set ofN-dimensional bins and returns the number of points (or total weight) in each bin.
inputmust 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 sequenceof bin edges. Bin edges may be specified explicitly by passing a sequence of 1Dtensors. Alternatively, bin edges may be constructed automatically by passing asequence of integers specifying the number of equal-width bins in each dimension.
- For each N-dimensional point in input:
- Each of its coordinates is binned independently among the bin edges
corresponding to its dimension
- Binning results are combined to identify the N-dimensional bin (if any)
into which the point falls
If the point falls into a bin, the bin’s count (or total weight) is incremented
Points which do not fall into any bin do not contribute to the output
binscan be a sequence of N 1D tensors, a sequence of N ints, or a single int.If
binsis a sequence of N 1D tensors, it explicitly specifies the N sequencesof bin edges. Each 1D tensor should contain a strictly increasing sequence with atleast one element. A sequence of K bin edges defines K-1 bins, explicitly specifyingthe left and right edges of all bins. Every bin is inclusive of its left edge. Onlythe rightmost bin is inclusive of its right edge.If
binsis a sequence of N ints, it specifies the number of equal-width binsin each dimension. By default, the leftmost and rightmost bin edges in each dimensionare determined by the minimum and maximum elements of the input tensor in thecorresponding dimension. Therangeargument can be provided to manuallyspecify the leftmost and rightmost bin edges in each dimension.If
binsis an int, it specifies the number of equal-width bins for all dimensions.Note
See also
torch.histogram(), which specifically computes 1D histograms.Whiletorch.histogramdd()infers the dimensionality of its bins andbinned values from the shape ofinput,torch.histogram()accepts and flattensinputof any shape.- Parameters
input (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.
- Keyword Arguments
range (sequence offloat) – Defines the leftmost and rightmost bin edgesin each dimension.
weight (Tensor) – By default, each value in the input has weight 1. If a weighttensor is passed, each N-dimensional coordinate in inputcontributes its associated weight towards its bin’s result.The weight tensor should have the same shape as the
inputtensor excluding its innermost dimension N.density (bool) – 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.
- Returns
N-dimensional Tensor containing the values of the histogram.bin_edges(Tensor[]): sequence of N 1D Tensors containing the bin edges.
- Return type
hist (Tensor)
Example:
>>>torch.histogramdd(torch.tensor([[0.,1.],[1.,0.],[2.,0.],[2.,2.]]),bins=[3,3],...weight=torch.tensor([1.,2.,4.,8.])) torch.return_types.histogramdd( hist=tensor([[0., 1., 0.], [2., 0., 0.], [4., 0., 8.]]), bin_edges=(tensor([0.0000, 0.6667, 1.3333, 2.0000]), tensor([0.0000, 0.6667, 1.3333, 2.0000])))>>>torch.histogramdd(torch.tensor([[0.,0.],[1.,1.],[2.,2.]]),bins=[2,2],...range=[0.,1.,0.,1.],density=True) torch.return_types.histogramdd( hist=tensor([[2., 0.], [0., 2.]]), bin_edges=(tensor([0.0000, 0.5000, 1.0000]), tensor([0.0000, 0.5000, 1.0000])))