SciPy

scipy.sparse.linalg

Sparse linear algebra (scipy.sparse.linalg)

Abstract linear operators

LinearOperator(dtype, shape) Common interface for performing matrix vector products Many iterative methods (e.g.
aslinearoperator(A) Return A as a LinearOperator.

Matrix Operations

inv(A) Compute the inverse of a sparse matrix :Parameters: A : (M,M) ndarray or sparse matrix square matrix to be inverted :Returns: Ainv : (M,M) ndarray or sparse matrix inverse of A ..
expm(A) Compute the matrix exponential using Pade approximation.
expm_multiply(A, B[, start, stop, num, endpoint]) Compute the action of the matrix exponential of A on B.

Matrix norms

onenormest(A[, t, itmax, compute_v, compute_w]) Compute a lower bound of the 1-norm of a sparse matrix.

Solving linear problems

Direct methods for linear equation systems:

spsolve(A, b[, permc_spec, use_umfpack]) Solve the sparse linear system Ax=b, where b may be a vector or a matrix.
factorized(A) Return a fuction for solving a sparse linear system, with A pre-factorized.

Iterative methods for linear equation systems:

bicg(A, b[, x0, tol, maxiter, xtype, M, ...]) Use BIConjugate Gradient iteration to solve A x = b :Parameters: A : {sparse matrix, dense matrix, LinearOperator} The real or complex N-by-N matrix of the linear system It is required that the linear operator can produce Ax and A^T x.
bicgstab(A, b[, x0, tol, maxiter, xtype, M, ...]) Use BIConjugate Gradient STABilized iteration to solve A x = b :Parameters: A : {sparse matrix, dense matrix, LinearOperator} The real or complex N-by-N matrix of the linear system A must represent a hermitian, positive definite matrix b : {array, matrix} Right hand side of the linear system.
cg(A, b[, x0, tol, maxiter, xtype, M, callback]) Use Conjugate Gradient iteration to solve A x = b :Parameters: A : {sparse matrix, dense matrix, LinearOperator} The real or complex N-by-N matrix of the linear system A must represent a hermitian, positive definite matrix b : {array, matrix} Right hand side of the linear system.
cgs(A, b[, x0, tol, maxiter, xtype, M, callback]) Use Conjugate Gradient Squared iteration to solve A x = b :Parameters: A : {sparse matrix, dense matrix, LinearOperator} The real-valued N-by-N matrix of the linear system b : {array, matrix} Right hand side of the linear system.
gmres(A, b[, x0, tol, restart, maxiter, ...]) Use Generalized Minimal RESidual iteration to solve A x = b.
lgmres(A, b[, x0, tol, maxiter, M, ...]) Solve a matrix equation using the LGMRES algorithm.
minres(A, b[, x0, shift, tol, maxiter, ...]) Use MINimum RESidual iteration to solve Ax=b MINRES minimizes norm(A*x - b) for a real symmetric matrix A.
qmr(A, b[, x0, tol, maxiter, xtype, M1, M2, ...]) Use Quasi-Minimal Residual iteration to solve A x = b :Parameters: A : {sparse matrix, dense matrix, LinearOperator} The real-valued N-by-N matrix of the linear system.

Iterative methods for least-squares problems:

lsqr(A, b[, damp, atol, btol, conlim, ...]) Find the least-squares solution to a large, sparse, linear system of equations.
lsmr(A, b[, damp, atol, btol, conlim, ...]) Iterative solver for least-squares problems.

Matrix factorizations

Eigenvalue problems:

eigs(A[, k, M, sigma, which, v0, ncv, ...]) Find k eigenvalues and eigenvectors of the square matrix A.
eigsh(A[, k, M, sigma, which, v0, ncv, ...]) Find k eigenvalues and eigenvectors of the real symmetric square matrix or complex hermitian matrix A.
lobpcg(A, X[, B, M, Y, tol, maxiter, ...]) Locally Optimal Block Preconditioned Conjugate Gradient Method (LOBPCG) LOBPCG is a preconditioned eigensolver for large symmetric positive definite (SPD) generalized eigenproblems.

Singular values problems:

svds(A[, k, ncv, tol, which, v0, maxiter, ...]) Compute the largest k singular values/vectors for a sparse matrix.

Complete or incomplete LU factorizations

splu(A[, permc_spec, diag_pivot_thresh, ...]) Compute the LU decomposition of a sparse, square matrix.
spilu(A[, drop_tol, fill_factor, drop_rule, ...]) Compute an incomplete LU decomposition for a sparse, square matrix.
SuperLU LU factorization of a sparse matrix.

Exceptions

ArpackNoConvergence(msg, eigenvalues, ...) ARPACK iteration did not converge ..
ArpackError(info[, infodict]) ARPACK error

Functions

all(a[, axis, out, keepdims]) Test whether all array elements along a given axis evaluate to True.
amax(a[, axis, out, keepdims]) Return the maximum of an array or maximum along an axis.
amin(a[, axis, out, keepdims]) Return the minimum of an array or minimum along an axis.
array(object[, dtype, copy, order, subok, ndmin]) Create an array.
asarray(a[, dtype, order]) Convert the input to an array.
aslinearoperator(A) Return A as a LinearOperator.
bicg(A, b[, x0, tol, maxiter, xtype, M, ...]) Use BIConjugate Gradient iteration to solve A x = b :Parameters: A : {sparse matrix, dense matrix, LinearOperator} The real or complex N-by-N matrix of the linear system It is required that the linear operator can produce Ax and A^T x.
bicgstab(A, b[, x0, tol, maxiter, xtype, M, ...]) Use BIConjugate Gradient STABilized iteration to solve A x = b :Parameters: A : {sparse matrix, dense matrix, LinearOperator} The real or complex N-by-N matrix of the linear system A must represent a hermitian, positive definite matrix b : {array, matrix} Right hand side of the linear system.
cg(A, b[, x0, tol, maxiter, xtype, M, callback]) Use Conjugate Gradient iteration to solve A x = b :Parameters: A : {sparse matrix, dense matrix, LinearOperator} The real or complex N-by-N matrix of the linear system A must represent a hermitian, positive definite matrix b : {array, matrix} Right hand side of the linear system.
cgs(A, b[, x0, tol, maxiter, xtype, M, callback]) Use Conjugate Gradient Squared iteration to solve A x = b :Parameters: A : {sparse matrix, dense matrix, LinearOperator} The real-valued N-by-N matrix of the linear system b : {array, matrix} Right hand side of the linear system.
dot(a, b[, out]) Dot product of two arrays.
eigs(A[, k, M, sigma, which, v0, ncv, ...]) Find k eigenvalues and eigenvectors of the square matrix A.
eigsh(A[, k, M, sigma, which, v0, ncv, ...]) Find k eigenvalues and eigenvectors of the real symmetric square matrix or complex hermitian matrix A.
empty(shape[, dtype, order]) Return a new array of given shape and type, without initializing entries.
empty_like(a[, dtype, order, subok]) Return a new array with the same shape and type as a given array.
expm(A) Compute the matrix exponential using Pade approximation.
expm_multiply(A, B[, start, stop, num, endpoint]) Compute the action of the matrix exponential of A on B.
factorized(A) Return a fuction for solving a sparse linear system, with A pre-factorized.
fastCopyAndTranspose(a)
geterrobj() Return the current object that defines floating-point error handling.
gmres(A, b[, x0, tol, restart, maxiter, ...]) Use Generalized Minimal RESidual iteration to solve A x = b.
inv(A) Compute the inverse of a sparse matrix :Parameters: A : (M,M) ndarray or sparse matrix square matrix to be inverted :Returns: Ainv : (M,M) ndarray or sparse matrix inverse of A ..
issparse(x)
lgmres(A, b[, x0, tol, maxiter, M, ...]) Solve a matrix equation using the LGMRES algorithm.
lobpcg(A, X[, B, M, Y, tol, maxiter, ...]) Locally Optimal Block Preconditioned Conjugate Gradient Method (LOBPCG) LOBPCG is a preconditioned eigensolver for large symmetric positive definite (SPD) generalized eigenproblems.
lsmr(A, b[, damp, atol, btol, conlim, ...]) Iterative solver for least-squares problems.
lsqr(A, b[, damp, atol, btol, conlim, ...]) Find the least-squares solution to a large, sparse, linear system of equations.
minres(A, b[, x0, shift, tol, maxiter, ...]) Use MINimum RESidual iteration to solve Ax=b MINRES minimizes norm(A*x - b) for a real symmetric matrix A.
norm(x[, ord]) Norm of a sparse matrix This function is able to return one of seven different matrix norms, depending on the value of the ord parameter.
onenormest(A[, t, itmax, compute_v, compute_w]) Compute a lower bound of the 1-norm of a sparse matrix.
product(a[, axis, dtype, out, keepdims]) Return the product of array elements over a given axis.
qmr(A, b[, x0, tol, maxiter, xtype, M1, M2, ...]) Use Quasi-Minimal Residual iteration to solve A x = b :Parameters: A : {sparse matrix, dense matrix, LinearOperator} The real-valued N-by-N matrix of the linear system.
ravel(a[, order]) Return a contiguous flattened array.
rollaxis(a, axis[, start]) Roll the specified axis backwards, until it lies in a given position.
size(a[, axis]) Return the number of elements along a given axis.
spilu(A[, drop_tol, fill_factor, drop_rule, ...]) Compute an incomplete LU decomposition for a sparse, square matrix.
splu(A[, permc_spec, diag_pivot_thresh, ...]) Compute the LU decomposition of a sparse, square matrix.
spsolve(A, b[, permc_spec, use_umfpack]) Solve the sparse linear system Ax=b, where b may be a vector or a matrix.
sum(a[, axis, dtype, out, keepdims]) Sum of array elements over a given axis.
svds(A[, k, ncv, tol, which, v0, maxiter, ...]) Compute the largest k singular values/vectors for a sparse matrix.
transpose(a[, axes]) Permute the dimensions of an array.
use_solver(**kwargs) Valid keyword arguments with defaults (other ignored):: useUmfpack = True assumeSortedIndices = False The default sparse solver is umfpack when available.
zeros(shape[, dtype, order]) Return a new array of given shape and type, filled with zeros.

Classes

LinearOperator(dtype, shape) Common interface for performing matrix vector products Many iterative methods (e.g.
SuperLU LU factorization of a sparse matrix.
Tester Nose test runner.
broadcast Produce an object that mimics broadcasting.
cdouble Composed of two 64 bit floats ..
complexfloating
csingle Composed of two 32 bit floats ..
double 64-bit floating-point number. Character code ‘d’. Python float compatible.
errstate(**kwargs) Context manager for floating-point error handling.
finfo Machine limits for floating point types.
inexact
intc
longdouble
single 32-bit floating-point number. Character code ‘f’. C float compatible.

Exceptions

ArpackError(info[, infodict]) ARPACK error
ArpackNoConvergence(msg, eigenvalues, ...) ARPACK iteration did not converge ..
MatrixRankWarning