Skip to content

Instantly share code, notes, and snippets.

@Robofied
Created February 15, 2019 15: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/94714e81c6aae3a841c34f94cd81dd30 to your computer and use it in GitHub Desktop.
Save Robofied/94714e81c6aae3a841c34f94cd81dd30 to your computer and use it in GitHub Desktop.
Numpy
y= a.mean(axis=1)
print(y)
#[Output]:
#[0.5 2.5 4.5]
y.reshape(3,1)
#[Output]:
#array([[0.5],
# [2.5],
# [4.5]])
print(a-y.reshape(3,1))
#[Output]:
#[[-0.5 0.5]
# [-0.5 0.5]
# [-0.5 0.5]]
z = np.sum(np.square(a-y.reshape(3,1)),axis=1)
print(z)
#[Output]:
#[0.5 0.5 0.5]
print(z/a.shape[1])
#[Output]:
#array([0.25, 0.25, 0.25])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment