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 |
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]] |
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] |
print(np.quantile(x, np.arange(0.25, 1, 0.25))) # Computing the quartiles of all values # [3.5 5. 7.25]