scipy
\(\color{red}{简介}\)
scipy包含致力于科学计算中常见问题的各个工具箱。它的不同子模块相应于不同的应用。像插值,积分,优化,图像处理,统计,特殊函数等等。
模块 功能
scipy.cluster 矢量量化 / K-均值
scipy.constants 物理和数学常数
scipy.fftpack 傅里叶变换
scipy.integrate 积分程序
scipy.interpolate 插值
scipy.io 数据输入输出
scipy.linalg 线性代数程序
scipy.ndimage n维图像包
scipy.odr 正交距离回归
scipy.optimize 优化(提供了函数最小值,曲线拟合和寻找等式的根的有用算法)
scipy.signal 信号处理
scipy.sparse 稀疏矩阵
scipy.spatial 空间数据结构和算法
scipy.special 任何特殊数学函数
scipy.stats 统计
#读取matlab文件
from scipy import io as spio
spio.loadmat('xx.mat')
#读取图片
from scipy import misc
misc.imread('scikit.png')
\(\color{blue}{sparse matrix classes}\)
bsr_matrix(arg1[, shape, dtype, copy, blocksize]) Block Sparse Row matrix
coo_matrix(arg1[, shape, dtype, copy]) A sparse matrix in COOrdinate format.
csc_matrix(arg1[, shape, dtype, copy]) Compressed Sparse Column matrix
csr_matrix(arg1[, shape, dtype, copy]) Compressed Sparse Row matrix
dia_matrix(arg1[, shape, dtype, copy]) Sparse matrix with DIAgonal storage
dok_matrix(arg1[, shape, dtype, copy]) Dictionary Of Keys based sparse matrix.
lil_matrix(arg1[, shape, dtype, copy]) Row-based linked list sparse matrix
spmatrix([maxprint]) This class provides a base class for all sparse matrices.
\(\color{blue}{sparse matrix function}\)
eye(m[, n, k, dtype, format]) Sparse matrix with ones on diagonal
identity(n[, dtype, format]) Identity matrix in sparse format
kron(A, B[, format]) kronecker product of sparse matrices A and B
kronsum(A, B[, format]) kronecker sum of sparse matrices A and B
diags(diagonals[, offsets, shape, format, dtype]) Construct a sparse matrix from diagonals.
spdiags(data, diags, m, n[, format]) Return a sparse matrix from diagonals.
block_diag(mats[, format, dtype]) Build a block diagonal sparse matrix from provided matrices.
tril(A[, k, format]) Return the lower triangular portion of a matrix in sparse format
triu(A[, k, format]) Return the upper triangular portion of a matrix in sparse format
bmat(blocks[, format, dtype]) Build a sparse matrix from sparse sub-blocks
hstack(blocks[, format, dtype]) Stack sparse matrices horizontally (column wise)
vstack(blocks[, format, dtype]) Stack sparse matrices vertically (row wise)
rand(m, n[, density, format, dtype, ...]) Generate a sparse matrix of the given shape and density with uniformly distributed values.
random(m, n[, density, format, dtype, ...]) Generate a sparse matrix of the given shape and density with randomly distributed values.
Save and load sparse matrices:
save_npz(file, matrix[, compressed]) Save a sparse matrix to a file using .npz format.
load_npz(file) Load a sparse matrix from a file using .npz format.
Sparse matrix tools:
find(A) Return the indices and values of the nonzero elements of a matrix
Identifying sparse matrices:
issparse(x)
isspmatrix(x)
isspmatrix_csc(x)
isspmatrix_csr(x)
isspmatrix_bsr(x)
isspmatrix_lil(x)
isspmatrix_dok(x)
isspmatrix_coo(x)
isspmatrix_dia(x)
\(\color{green}{eye}\)
from scipy import sparse
sparse.eye(3).toarray()
w=sparse.eye(2,3,k=1)
w.transpose()#转置
w.diagnoal()#主对角线上元素
\(\color{blue}{linalg}\)
linalg.solve(A,b)#Ax=b

浙公网安备 33010602011771号