Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Numpy
import numpy as np
a = np.arange(6).reshape(3,2)
print(a)
#[Output]:
#array([[0, 1],
# [2, 3],
# [4, 5]])
print(np.median(a))
#[Output]:
#2.5
print(p.median(a, axis=0))
#[Output]:
#array([2., 3.])
print(np.median(a, axis=1))
#[Output]:
#array([0.5, 2.5, 4.5])
print(np.var(a))
#[Output]:
#2.9166666666666665
print(np.var(a,axis=0))
#[Output]:
#array([2.66666667, 2.66666667])
print(np.var(a,axis=1))
#[Output]:
#array([0.25, 0.25, 0.25])
## Core implementation of variance
## This is for whole flattened array
y = a.mean()
print(y)
#[Output]:
#2.5
z = np.sum(np.square(a-y))
print(z)
#[Output]:
#17.5
print(z/a.size)
#[Output]:
#2.9166666666666665
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.