latest (dev)
Copy
Latest development documentation · Updated 2026-10-15
tensorplay._composite_funcs API
Functions 3
histogram
functionFull reference ↗- tensorplay._composite_funcs.histogram(input, bins, *, range=None, weight=None, density=False, out=None)[source]
Computes a histogram of the values in a tensor.
binscan be an integer or a 1D tensor.If
binsis an int, it specifies the number of equal-width bins. By default, the lower and upper range of the bins is determined by the minimum and maximum elements of the input tensor. Therangeargument can be provided to specify a range for the bins.If
binsis a 1D tensor, it specifies the sequence of bin edges including the rightmost edge. It should contain at least 2 elements and its elements should be increasing.- Parameters:
input (Tensor) – the input tensor.
bins – int or 1D Tensor. If int, defines the number of equal-width bins. If tensor, defines the sequence of bin edges including the rightmost edge.
- Keyword Arguments:
weight (Tensor) – If provided, weight should have the same shape as input. Each value in input contributes its associated weight towards its bin’s result.
density (bool) – If False, the result will contain the count (or total weight) in each bin. If True, the result is the value of the probability density function over the bins, normalized such that the integral over the range of the bins is 1.
out (Tensor, optional) – the output tensor. (tuple, optional): The result tuple of two output tensors (hist, bin_edges).
- Returns:
1D Tensor containing the values of the histogram. bin_edges(Tensor): 1D Tensor containing the edges of the histogram bins.
- Return type:
hist (Tensor)
Example:
>>> tensorplay.histogram(tensorplay.tensor([1., 2, 1]), bins=4, range=(0., 3.), weight=tensorplay.tensor([1., 2., 4.])) (tensor([ 0., 5., 2., 0.]), tensor([0., 0.75, 1.5, 2.25, 3.])) >>> tensorplay.histogram(tensorplay.tensor([1., 2, 1]), bins=4, range=(0., 3.), weight=tensorplay.tensor([1., 2., 4.]), density=True) (tensor([ 0., 0.9524, 0.3810, 0.]), tensor([0., 0.75, 1.5, 2.25, 3.]))
nanquantile
functionFull reference ↗- tensorplay._composite_funcs.nanquantile(input, q, dim=None, keepdim=False, *, interpolation='linear', out=None) Tensor[source]
This is a variant of
tensorplay.quantile()that “ignores”NaNvalues, computing the quantilesqas ifNaNvalues ininputdid not exist. If all values in a reduced row areNaNthen the quantiles for that reduction will beNaN. See the documentation fortensorplay.quantile().- Parameters:
- Keyword Arguments:
Example:
>>> t = tensorplay.tensor([float('nan'), 1, 2]) >>> t.quantile(0.5) tensor(nan) >>> t.nanquantile(0.5) tensor(1.5000) >>> t = tensorplay.tensor([[float('nan'), float('nan')], [1, 2]]) >>> t tensor([[nan, nan], [1., 2.]]) >>> t.nanquantile(0.5, dim=0) tensor([1., 2.]) >>> t.nanquantile(0.5, dim=1) tensor([ nan, 1.5000])
quantile
functionFull reference ↗- tensorplay._composite_funcs.quantile(input, q, dim=None, keepdim=False, *, interpolation='linear', out=None) Tensor[source]
Computes the q-th quantiles of each row of the
inputtensor along the dimensiondim.To compute the quantile, we map q in [0, 1] to the range of indices [0, n] to find the location of the quantile in the sorted input. If the quantile lies between two data points
a < bwith indicesiandjin the sorted order, result is computed according to the giveninterpolationmethod as follows:linear:a + (b - a) * fraction, wherefractionis the fractional part of the computed quantile index.lower:a.higher:b.nearest:aorb, whichever’s index is closer to the computed quantile index (rounding down for .5 fractions).midpoint:(a + b) / 2.
If
qis a 1D tensor, the first dimension of the output represents the quantiles and has size equal to the size ofq, the remaining dimensions are what remains from the reduction.Note
By default
dimisNoneresulting in theinputtensor being flattened before computation.- Parameters:
- Keyword Arguments:
Example:
>>> a = tensorplay.randn(2, 3) >>> a tensor([[ 0.0795, -1.2117, 0.9765], [ 1.1707, 0.6706, 0.4884]]) >>> q = tensorplay.tensor([0.25, 0.5, 0.75]) >>> tensorplay.quantile(a, q, dim=1, keepdim=True) tensor([[[-0.5661], [ 0.5795]], [[ 0.0795], [ 0.6706]], [[ 0.5280], [ 0.9206]]]) >>> tensorplay.quantile(a, q, dim=1, keepdim=True).shape tensorplay.Size([3, 2, 1]) >>> a = tensorplay.arange(4.) >>> a tensor([0., 1., 2., 3.]) >>> tensorplay.quantile(a, 0.6, interpolation='linear') tensor(1.8000) >>> tensorplay.quantile(a, 0.6, interpolation='lower') tensor(1.) >>> tensorplay.quantile(a, 0.6, interpolation='higher') tensor(2.) >>> tensorplay.quantile(a, 0.6, interpolation='midpoint') tensor(1.5000) >>> tensorplay.quantile(a, 0.6, interpolation='nearest') tensor(2.) >>> tensorplay.quantile(a, 0.4, interpolation='nearest') tensor(1.)
Help improve this page
Found an error, an unclear step, or a missing example?

