Click on the links to get the high-resolution cheat sheets.
The Python numerical computation library called NumPy provides many linear algebra functions that may be useful for a machine learning practitioner. In this tutorial, you will discover the key functions for working with vectors and matrices that you may find useful as a machine learning practitioner.
There are many ways to create NumPy arrays.
from numpy import array
A = array([[1,2,3],[1,2,3],[1,2,3]])
from numpy import empty
A = empty([3,3])
from numpy import zeros
A = zeros([3,5])
from numpy import ones
A = ones([5, 5])
A vector is a list or column of scalars.
c = a + b
c = a - b
c = a * b
c = a / b
c = a.dot(b)
c = a @ b
c = a * 2.2
from numpy.linalg import norm
l2 = norm(v)
A matrix is a two-dimensional array of scalars.
C = A + B
1 |
C = A - B
C = A * B
C = A / B
C = A.dot(B)
C = A @ B
C = A.dot(b)
C = A @ b
C = A.dot(2.2)
C = A * 2.2
Different types of matrices are often used as elements in broader calculations.
# lowerfrom numpy import tril
lower = tril(M)
# upperfrom numpy import triu
upper = triu(M)
from numpy import diag
d = diag(M)
from numpy import eye
I = eye(3)
Matrix operations are often used as elements in broader calculations.
B = A.T
from numpy.linalg import inv
B = inv(A)
from numpy import trace
B = trace(A)
from numpy.linalg import det
B = det(A)
from numpy.linalg import matrix_rank
r = matrix_rank(A)
Matrix factorization, or matrix decomposition, breaks a matrix down into its constituent parts to make other operations simpler and more numerically stable.
from scipy.linalg import lu
P, L, U = lu(A)
from numpy.linalg import qr
Q, R = qr(A, 'complete')
from numpy.linalg import eig
values, vectors = eig(A)
from scipy.linalg import svd
U, s, V = svd(A)
Statistics summarize the contents of vectors or matrices and are often used as components in broader operations.
from numpy import mean
result = mean(v)
from numpy import var
result = var(v, ddof=1)
from numpy import std
result = std(v, ddof=1)
from numpy import cov
sigma = cov(v1, v2)
from numpy.linalg import lstsq
b = lstsq(X, y)
Source:
https://medium.com/analytics-vidhya/data-science-cheat-sheets-109ddcb1aca8
https://machinelearningmastery.com/linear-algebra-cheat-sheet-for-machine-learning/