forked from lazyprogrammer/machine_learning_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
numpy
5u2ie edited this page Dec 13, 2019
·
3 revisions
-
normal list built-in methods don't work on numpy arrays
-
in python + just concatenates
-
in numpy + it does element-wise vector addition
-
has instance methods: dot(), sum()
-
has linalg methods:
- np.linalg.norm(A)
- np.linalg.inv(A)
- np.linalg.det(A)
- np.linalg.diag(A)
-
matrix datatypes
- np.matrix, np.array (just use the array always)
- can be sliced
-
matrix methods:
- np.mean(), .var()
- np.trace(a) -- sum of the diagonal
C = sum over i {A(i)B(i)}
a.dot(b) SAME AS np.inner(a,b)
- inner dimensions of the 2 matrices have to match
- sum of dot products for each pair
- using * in numpy
- when calculating the covariance of
- C(i,j) = A(i)B(j)
- np.outer()
- often apply this to covariance matrix of a dataset (symmetrical)
- to get covariance: np.cov(X.T)
- np.linalg.eig() for
- np.linalg.eigh(cov) for symmetric (equal to the transpose of itself) / Hermitian matrices (equal to the conjugate transpose of itself)
Ax = b
A - a matrix x - column we are trying to solve for b = vector of numbers
solution: multiply by A(-1) (A inverse) on both sides
x = np.linalg.inv(A).dot(b)
-- alternatively: x = np.linalg.solve(A,b)