kuniga.me > Docs > Numpy Cheatsheet
Assuming numpy is imported as:
Un-initialized vector of size N:
Similar versions for vectors filled with 1s: ones
, ans 0s: zeros
. Note that np.empty(shape=N)
is different from np.empty(shape=(N, 1))
. The former has x[N]
, while the latter x[N, 1]
.
To flatten a matrix m(Nx1)
to a vector v(N)
:
Un-initialized matrix of size N x M:
Similar versions for vectors filled with 1s: ones
, and 0s: zeros
.
Number of rows:
Number of columns:
Initialize from nested Python lists:
Transpose:
Einstein Summation:
This article is a great introduction:
https://ajcr.net/Basic-guide-to-einsum/