Skip to content

Numpy

Create a numpy from list

python
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))

argmax

Return the indices of the maximum values along the axis.

python
numpy.argmax(a, axis=None, out=None, *, keepdims=<no value>)
  • a: array_like
    Input array.
  • axis: int, optional
    By default, the index is into the flattened array, otherwise along the specified axis.
python
import numpy as np
a = np.arange(6).reshape(2,3) + 10
# array([[10, 11, 12],
#        [13, 14, 15]])
np.argmax(a)  # 5
np.argmax(a, axis=0) # array([1, 1, 1])
np.argmax(a, axis=1) #array([2, 2])
np.argmax(a, axis=-1) #array([2, 2])