Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Robofied
Last active February 15, 2019 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Robofied/2d8b38e398562a2da6d847c1a68dd608 to your computer and use it in GitHub Desktop.
Save Robofied/2d8b38e398562a2da6d847c1a68dd608 to your computer and use it in GitHub Desktop.
Numpy
import numpy as np
a = np.arange(6).reshape((3,2))
print(a)
#[Output]:
#array([[0, 1],
# [2, 3],
# [4, 5]])
## amin() function to find minimum in array.
## Similarly we can go for amax() to find maximum
## Return minimum along flattened array.
print(np.amin(a))
#[Output]:
#0
## Minimum along columns
np.amin(a,axis=0)
#[Output]:
#array([0, 1])
##Minimum along rows
np.amax(a,axis=1)
#[Output]:
#array([1, 3, 5])
## percentile() function to find percentile along the specified axis
np.percentile(a,q=0)
#[Output]:
#0.0
print(np.percentile(a,q=50))
print(np.percentile(a,q=50,axis=0))
#[Output]:
#2.5
#[2. 3.]
np.percentile(a,q=100)
#[Output]:
#5.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment