quantile

quantile(data: Tensor, dim: tuple[int, ...] | int | None = None, keepdim: bool = False, q: float = 0.5, interpolation: Literal['linear', 'lowest', 'higher', 'nearest', 'midpoint'] = 'linear', **kwargs) Tensor[source]

Returns a tensor with dimensions reduced by taking the arithmetic mean.

This is a wrapper around torch.quantile() with arguments rearranged and defaults provided for compatibility. By default, the median is computed (q=0.5).

The interpolation methods are as follows, when a is the value with the lower discrete index, b is the value with the higher discrete index, and k is the continuous index for the quantile.

  • "linear": a + (b - a) * k % 1

  • "lower": a

  • "higher": b

  • "nearest": b if (k % 1) > 0.5 else a

  • "midpoint": (a + b) / 2

Parameters:
  • data (torch.Tensor) – tensor to which operations should be applied.

  • dim (tuple[int, ...] | int | None, optional) – dimension(s) along which the reduction should be applied, all dimensions when None. Defaults to None.

  • keepdim (bool, optional) – if the dimensions should be retained in the output. Defaults to False.

  • q (float, optional) – \(q^\text{th}\) quantile to take. Defaults to 0.5.

  • interpolation (str, optional) – method of interpolation when the quantile lies between two data points. Defaults to "linear".

Returns:

dimensionally reduced tensor.

Return type:

torch.Tensor