# quantile#

ivy.quantile(a, q, /, *, axis=None, keepdims=False, interpolation='linear', out=None)[source]#

Compute the q-th quantile of the data along the specified axis.

Parameters:
• a (`Array`) – Input array.

• q (`Union`[`Array`, `float`]) – Quantile or sequence of quantiles to compute, which must be between 0 and 1 inclusive.

• axis (`Optional`[`Union`[`int`, `Sequence`[`int`]]], default: `None`) – Axis or axes along which the quantiles are computed. The default is to compute the quantile(s) along a flattened version of the array.

• keepdims (`bool`, default: `False`) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original array a.

• interpolation (`str`, default: `'linear'`) – {‘nearest’, ‘linear’, ‘lower’, ‘higher’, ‘midpoint’, ‘nearest_jax’}. Default value: ‘linear’. This specifies the interpolation method to use when the desired quantile lies between two data points i < j: - linear: i + (j - i) * fraction, where fraction is the fractional part of the index surrounded by i and j. - lower: i. - higher: j. - nearest: i or j, whichever is nearest. - midpoint: (i + j) / 2. linear and midpoint interpolation do not work with integer dtypes. - nearest_jax: provides jax-like computation for interpolation=’nearest’.

• out (`Optional`[`Array`], default: `None`) – optional output array, for writing the result to.

Return type:

`Array`

Returns:

ret – A (rank(q) + N - len(axis)) dimensional array of same dtype as a, or, if axis is None, a rank(q) array. The first rank(q) dimensions index quantiles for different values of q.

Examples

```>>> a = ivy.array([[10., 7., 4.], [3., 2., 1.]])
>>> q = ivy.array(0.5)
>>> ivy.quantile(a, q)
ivy.array(3.5)
```
```>>> a = ivy.array([[10., 7., 4.], [3., 2., 1.]])
>>> q = 0.5
>>> ivy.quantile(a, q)
ivy.array(3.5)
```
```>>> ivy.quantile(a, q, axis=0)
ivy.array([6.5, 4.5, 2.5])
```
```>>> ivy.quantile(a, q, axis=1)
ivy.array([7.,  2.])
```
```>>> ivy.quantile(a, q, axis=1, keepdims=True)
ivy.array([[7.],[2.]])
```
```>>> a = ivy.array([1., 2., 3., 4.])
>>> q = ivy.array([0.3, 0.7])
>>> ivy.quantile(a, q, interpolation='lower')
ivy.array([1., 3.])
```
Array.quantile(self, q, /, *, axis=None, keepdims=False, interpolation='linear', out=None)[source]#

ivy.Array instance method variant of ivy.quantile. This method simply wraps the function, and so the docstring for ivy.quantile also applies to this method with minimal changes.

Parameters:
• self (`Array`) – Input array.

• q (`Union`[`Array`, `float`]) – Quantile or sequence of quantiles to compute, which must be between 0 and 1 inclusive.

• axis (`Optional`[`Union`[`int`, `Sequence`[`int`]]], default: `None`) – Axis or axes along which the quantiles are computed. The default is to compute the quantile(s) along a flattened version of the array.

• keepdims (`bool`, default: `False`) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original array a.

• interpolation (`str`, default: `'linear'`) – {‘nearest’, ‘linear’, ‘lower’, ‘higher’, ‘midpoint’}. Default value: ‘linear’. This specifies the interpolation method to use when the desired quantile lies between two data points i < j: - linear: i + (j - i) * fraction, where fraction is the fractional part of the index surrounded by i and j. - lower: i. - higher: j. - nearest: i or j, whichever is nearest. - midpoint: (i + j) / 2. linear and midpoint interpolation do not work with integer dtypes.

• out (`Optional`[`Array`], default: `None`) – optional output array, for writing the result to.

Return type:

`Array`

Returns:

ret – A (rank(q) + N - len(axis)) dimensional array of same dtype as a, or, if axis is None, a rank(q) array. The first rank(q) dimensions index quantiles for different values of q.

Examples

```>>> a = ivy.array([[10., 7., 4.], [3., 2., 1.]])
>>> q = ivy.array(0.5)
>>> a.quantile(q)
ivy.array(3.5)
```
```>>> a = ivy.array([[10., 7., 4.], [3., 2., 1.]])
>>> q = 0.5
>>> a.quantile(q)
ivy.array(3.5)
```
```>>> a.quantile(q, axis=0)
ivy.array([6.5, 4.5, 2.5])
```
```>>> a.quantile(q, axis=1)
ivy.array([7.,  2.])
```
```>>> a.quantile(q, axis=1, keepdims=True)
ivy.array([[7.],[2.]])
```
```>>> a = ivy.array([1., 2., 3., 4.])
>>> q = ivy.array([0.3, 0.7])
>>> a.quantile(q, interpolation='lower')
ivy.array([1., 3.])
```
Container.quantile(self, q, /, *, axis=None, keepdims=False, interpolation='linear', key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

ivy.Container instance method variant of ivy.quantile. This method simply wraps the function, and so the docstring for ivy.quantile also applies to this method with minimal changes.

Parameters:
• a – Input container including arrays.

• q (`Union`[`Array`, `float`, `Container`]) – Quantile or sequence of quantiles to compute, which must be between 0 and 1 inclusive.

• axis (`Optional`[`Union`[`int`, `Sequence`[`int`], `Container`]], default: `None`) – Axis or axes along which the quantiles are computed. The default is to compute the quantile(s) along a flattened version of the array.

• keepdims (`Union`[`bool`, `Container`], default: `False`) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original array a.

• interpolation (`Union`[`str`, `Container`], default: `'linear'`) – {‘nearest’, ‘linear’, ‘lower’, ‘higher’, ‘midpoint’}. Default value: ‘linear’. This specifies the interpolation method to use when the desired quantile lies between two data points i < j: - linear: i + (j - i) * fraction, where fraction is the fractional part of the index surrounded by i and j. - lower: i. - higher: j. - nearest: i or j, whichever is nearest. - midpoint: (i + j) / 2. linear and midpoint interpolation do not work with integer dtypes.

• out (`Optional`[`Container`], default: `None`) – optional output array, for writing the result to.

Return type:

`Container`

Returns:

ret – Container with (rank(q) + N - len(axis)) dimensional arrays of same dtype as input arrays in the container, or, if axis is None, rank(q) arrays. The first rank(q) dimensions index quantiles for different values of q.

Examples

With one `ivy.Container` input:

```>>> x = ivy.Container(a=ivy.array([[10., 7., 4.], [3., 2., 1.]]),
...                   b=ivy.array([1., 2., 3., 4.]))
>>> z = ivy.array([0.5])
>>> y = x.quantile(z)
>>> print(y)
{
a: ivy.array(3.5),
b: ivy.array(2.5)
}
```
```>>> x = ivy.Container(a=ivy.array([[10., 7., 4.], [3., 2., 1.]]),
...                   b=ivy.array([1., 2., 3., 4.]))
>>> z = ivy.array([0.5, 0.75])
>>> y = x.quantile(z)
>>> print(y)
{
a: ivy.array([3.5, 6.25]),
b: ivy.array([2.5, 3.25])
}
```
```>>> x = ivy.Container(a=ivy.array([[10., 7., 4.], [3., 2., 1.]]),
...                   b=ivy.array([1., 2., 3., 4.]))
>>> z = ivy.array([0.5, 0.75])
>>> y = x.quantile(z, axis = 0)
>>> print(y)
{
a: ivy.array([[6.5, 4.5, 2.5],
[8.25, 5.75, 3.25]]),
b: ivy.array([2.5, 3.25])
}
```
```>>> x = ivy.Container(a=ivy.array([[10., 7., 4.], [3., 2., 1.]]))
>>> z = ivy.array([0.5, 0.75])
>>> y = x.quantile(z, axis = 1, keepdims=True)
>>> print(y)
{
a: ivy.array([[[7.],
[2.]],
[[8.5],
[2.5]]])
}
```
```>>> x = ivy.Container(a=ivy.array([[10., 7., 4.], [3., 2., 1.]]),
...                   b=ivy.array([1., 2., 3., 4.]))
>>> z = ivy.array([0.3, 0.7])
>>> y = x.quantile(z, axis = 0, interpolation="lower")
>>> print(y)
{
a: ivy.array([[3., 2., 1.],
[3., 2., 1.]]),
b: ivy.array([1., 3.])
}
```