-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix_decompostion.py
More file actions
67 lines (48 loc) · 1.64 KB
/
Copy pathmatrix_decompostion.py
File metadata and controls
67 lines (48 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import numpy as np
from scipy.linalg import lu
def lu_decomposition(x: np.ndarray) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
"""
Perform LU decomposition of a matrix.
Args:
x (np.ndarray): The input matrix to decompose.
Returns:
tuple[np.ndarray, np.ndarray, np.ndarray]:
The permutation matrix P, lower triangular matrix L, and upper triangular matrix U.
"""
return lu(x)
def qr_decomposition(x: np.ndarray) -> tuple[np.ndarray, np.ndarray]:
"""
Perform QR decomposition of a matrix.
Args:
x (np.ndarray): The input matrix to decompose.
Returns:
tuple[np.ndarray, np.ndarray]: The orthogonal matrix Q and upper triangular matrix R.
"""
return np.linalg.qr(x)
def determinant(x: np.ndarray) -> np.ndarray:
"""
Calculate the determinant of a matrix.
Args:
x (np.ndarray): The input matrix.
Returns:
np.ndarray: The determinant of the matrix.
"""
return np.linalg.det(x)
def eigen(x: np.ndarray) -> tuple[np.ndarray, np.ndarray]:
"""
Compute the eigenvalues and right eigenvectors of a matrix.
Args:
x (np.ndarray): The input matrix.
Returns:
tuple[np.ndarray, np.ndarray]: The eigenvalues and the right eigenvectors of the matrix.
"""
return np.linalg.eig(x)
def svd(x: np.ndarray) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
"""
Perform Singular Value Decomposition (SVD) of a matrix.
Args:
x (np.ndarray): The input matrix to decompose.
Returns:
tuple[np.ndarray, np.ndarray, np.ndarray]: The matrices U, S, and V.
"""
return np.linalg.svd(x)