# SciPy如何计算线性代数？这里有详细解释————

SciPy建立在ATLAS LAPACK和BLAS库的基础上, 它提供了非常快速的线性代数功能。线性代数例程接受二维数组对象, 并且输出也以二维数组形式给出。如果我们想提高计算速度, 则必须在这种情况下进行深入研究。

``linalg.solve()``

### 线性方程

linalg.solve用于求解未知x, y值的线性方程a * x + b * y =Z。

x + 3y + 10z = 10

2x + 12y + 7z = 18

5x + 8y + 8z = 30

``````import numpy as np
from scipy import linalg
# We are trying to solve a linear algebra system which can be given as
#         x + 3y +10z = 10
#         2x + 12y + 7z = 18
#         5x + 8y + 8z = 30
# Creating input array
a = np.array([[1, 3, 10], [2, 12, 7], [5, 8, 8]])
# Solution Array
b = np.array([[10], [18], [30]])
# Solve the linear algebra
x = linalg.solve(a, b)
# Print results
print(x)
# Checking Results
print("\n Checking results, Vectors must be zeros")
print(a.dot(X) - b)``````

``````[[4.55393586]
[0.51311953]
[0.39067055]]

Checking results, Vectors must be zeros
[[0.]
[0.]
[0.]]``````

### 寻找决定因素

``````from scipy import linalg
import numpy as np
#Declaring the numpy array
A = np.array([[5, 9], [8, 4]])
#Passing the values to the det function
x = linalg.det(A)
#printing the result
print(x)``````

``-52``

### 特征值和特征向量

``````#importing the scipy and numpy packages
from scipy import linalg
import numpy as np
#Declaring the numpy array
a = np.array([[3, 2], [4, 6]])
#Passing the values to the eig function
l, v = linalg.eig(a)
#printing the result for eigenvalues
print(l)
#printing the result for eigenvectors
print(v)``````

``````[-0.37228132+0.j  5.37228132+0.j]
[[-0.82456484 -0.41597356]
[ 0.56576746 -0.90937671]]``````

### SciPy的svd

svd代表单值分解。矩阵A的唯一值分解是将A分解为三个矩阵A = UDVT的乘积, 其中U和V的列是正交的, 矩阵D是对角的, 并带有实数正项。