Show Menu
Cheatography

Numpy Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Numbers

zeros(
tuple
)
Generates an array of zeros, the dimensions are given by tuple.
ones(
tuple
)
Generates an array filled with 1, the dimensions are given by tuple.

np.ran­dom.*

random(
tuple
)
Uniformly samples numbers from [0, 1] into an array of size tuple.
random(*
tuple
)
Samples values from a Gaussian distri­bution with mean 0 and variance 1 into an array of size tuple.
Note: Each dimension is a separate argument.

Instance methods of np.array

mean()
Mean
var()
Variance

Matrices

np.diag(
list
)
Generates a matrix with the diagonal list and zeros elsewhere.
np.diag(
matrix
)
Extracts the diagonal of the given matrix or two-di­men­sional array.