Skip to content

Instantly share code, notes, and snippets.

@thekensta
Last active September 23, 2015 14:50
Show Gist options
  • Save thekensta/1a0c5aeab5eb17066f0f to your computer and use it in GitHub Desktop.
Save thekensta/1a0c5aeab5eb17066f0f to your computer and use it in GitHub Desktop.
Numpy Basic Operations Cheat Sheet
# Storing basic operations here, as I tend to forget them!
# Fill as required (or fill as forgotten?? :-)
# Repeat and Tile
# Repeat copies by element and flattens
# Tile copies sequences and preserves shape
a = np.array([1, 2, 3])
print(np.tile(a, 2))
# [1 2 3 1 2 3]
print(np.repeat(a, 2))
# [1 1 2 2 3 3]
a = np.array([[1, 2], [3, 4]])
print(np.tile(a, 2))
# [[1 2 1 2]
# [3 4 3 4]]
print(np.repeat(a, 2))
# [1 1 2 2 3 3 4 4]
# Ndarrays Vs Matrices
http://stackoverflow.com/questions/4151128/what-are-the-differences-between-numpy-arrays-and-matrices-which-one-should-i-u
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment