Let us explore NumPy’s quantile function.

## Function Syntax

The function syntax is as shown below:

## Function Parameters

The function accepts the parameters as follows:

- a â€“ the input array or array_like object.
- q â€“ your target quantile to calculate. You can also pass an inclusive sequence of quantiles ranging from 0 to 1.
- axis â€“ defines along which axis to calculate the quantile. By default, this value is set to None. Hence, the function will flatten the array and calculate the specified quantile.
- out â€“ sets an output array for the result.
- overwrite_input â€“ this parameter allows the function to modify the input array.
- method â€“ specifies the method used in estimating the quantile. Check the docs to discover the accepted values.

## Function Return Value

The function returns the q^{th} quantile of the specified array along the set axis.

## Example #1

The example shown below calculates a single quantile of a specified array.

import numpy as np

arr = np.array([10,20,30,40,50])

print(f".5 quantile: {np.quantile(arr, 0.5)}")

The code above should return the .5 quantile of the values in the provided array. The resulting output is:

## Example #2

To calculate multiple quantiles of a given array, we can do:

print(np.quantile(arr, [0.25, 0.25, 0.50]))

The above code calculates the quantiles as specified in the sequence.

The resulting values are as shown below:

## Example #3

To calculate the quantile of a 2D array along a specific axis:

print(np.quantile(arr, .25, axis=0))

For example, we calculate the .25th quantile along axis 0 of the input array in the code above.

The output is as shown:

## Example #4

You can also change the interpolation method as shown in the example below:

print(np.quantile(arr, .25, axis=0, interpolation='nearest'))

This results in the following array:

## Conclusion

Using this article, you should be familiar with the NumPy quantile function and how to use it to calculate the q^{th} quantiles of a given array along a specified axis.

See you at the next one!!!