Home>Article>Backend Development> How to use Python to find the norm and determinant of a matrix
In the function ofscipy.linalg, two parameters are often provided. One ischeck_finite. When it isTrue, a limited check will be performed. The other type isoverwrite_xxxx, which indicates whetherxxxxcan be overwritten during the calculation process. For the sake of simplicity, it will be said later thataprovides an overwrite switch, which means there is a parameteroverwrite_a. When it isTrue, a is allowed to be overwritten during the calculation process; If a limited check switch is provided, it means that thecheck_finiteparameter is provided.
The functionnormis provided inscipy.linalgto find the norm, which is defined as
norm(a, ord=None, axis=None, keepdims=False, check_finite=True)
Whereordis used to declare the order of the norm
| Matrix norm | Vector norm | |
|---|---|---|
| Frobenius norm | 2-Norm | |
Frobenius norm |
- | |
Nuclear norm | -
##inf | |
| max ( ∣ a ∣ ) | | -inf
|
| min ( ∣ a ∣ ) | | 0
- |
1 | max(sum(abs(a), axis=0))
||
| -1
||
| 2
2-Norm (maximum singular value) |
|
| -2 | Minimum singular value |
|
| ## If | a is a vector, if | ord
nuclear norm The number is also called the "trace norm" and represents the sum of all singular values of the matrix.Frobenius norm can be defined as

The essence is the natural generalization of the 2-norm of vectors in matrices.
In addition to
scipy.linalg,
norm
numpy.linalg
, and its parameters arenorm(x, ord=None, axis=None, keepdims=False)
The optional parameters oforder
are the same as thenorm
function inscipy.linalg
.
DeterminantInscipy.linalg, the determinant function isdet
a.The example is as follows
import numpy as np from scipy import linalg a = np.array([[1,2,3], [4,5,6], [7,8,9]]) linalg.det(a) # 0.0 a = np.array([[0,2,3], [4,5,6], [7,8,9]]) linalg.det(a) # 3.0
trace
scipy.linalg
does not provide the
trace
function, butumpy.trace(a, offset=0, axis1=0, axis2=1, dtype=None, out=None)
where
offset
is the offset, indicating the offset relative to the main diagonal
axis1, axis2represents the coordinate axis
The data type used to adjust the output value
>>> x = np.random.rand(3,3) >>> print(x) [[0.26832187 0.64615363 0.09006217] [0.63106319 0.65573765 0.35842304] [0.66629322 0.16999836 0.92357658]] >>> np.trace(x) 1.8476361016546932
The above is the detailed content of How to use Python to find the norm and determinant of a matrix. For more information, please follow other related articles on the PHP Chinese website!