Get Quantiles & Quartiles of NumPy Array in Python (Example Code)

On this page you’ll learn how to find the quantiles of a NumPy array in Python.

Preparing the Example

import numpy                                       # Load numpy
x = np.array([[8, 2, 1, 7, 7, 5],                  # Constructing a NumPy array in Python
              [4, 10, 5, 9, 1, 4]])
print(x)
# [[ 8  2  1  7  7  5]
#  [ 4 10  5  9  1  4]]

Example: Calculate Quartile of All Array Values in Python

print(np.quantile(x, np.arange(0.25, 1, 0.25)))    # Computing the quartiles of all values
# [3.5  5.   7.25]

Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top