@TOC
np.linalg.inv
np.linalg.inv(a)
计算一个矩阵的逆
Compute the (multiplicative) inverse of a matrix.
Given a square matrix a, return the matrix ainv satisfying
dot(a, ainv) = dot(ainv, a) = eye(a.shape[0]).
1 | import numpy as np |
np.linalg.norm
np.linalg.norm
计算矩阵或者向量的逆
Matrix or vector norm.
This function is able to return one of eight different matrix norms, or one of an infinite number of vector norms (described below), depending on the value of the
ordparameter.
1 | import numpy as np |
| ord | norm for matrices | norm for vectors |
|---|---|---|
| None | Frobenius norm | 2-norm |
| ‘fro’ | Frobenius norm | – |
| ‘nuc’ | nuclear norm | – |
| inf | max(sum(abs(x), axis=1)) | max(abs(x)) |
| -inf | min(sum(abs(x), axis=1)) | min(abs(x)) |
| 0 | – | sum(x != 0) |
| 1 | max(sum(abs(x), axis=0)) | as below |
| -1 | min(sum(abs(x), axis=0)) | as below |
| 2 | 2-norm (largest sing. value) | as below |
| -2 | smallest singular value | as below |
| other | – | sum(abs(x)ord)(1./ord) |