Skip to content

Numpy

Create a numpy from list

python
import numpy as np
data = np.array(list)
import numpy as np
data = np.array(list)

Compute the percentile

The numpy.percentile API compute the q-th percentile of the data along the specified axis.

python
import numpy as np
 
# 1D array
arr = [20, 2, 7, 1, 34]
print("arr : ", arr)
print("50th percentile of arr : ",
      np.percentile(arr, 50))
print("25th percentile of arr : ",
      np.percentile(arr, 25))
print("75th percentile of arr : ",
      np.percentile(arr, 75))
import numpy as np
 
# 1D array
arr = [20, 2, 7, 1, 34]
print("arr : ", arr)
print("50th percentile of arr : ",
      np.percentile(arr, 50))
print("25th percentile of arr : ",
      np.percentile(arr, 25))
print("75th percentile of arr : ",
      np.percentile(arr, 75))