0% found this document useful (0 votes)
137 views

Linear Algebra Using Sympy Cheat Sheet: by Via

This document provides a cheat sheet for performing linear algebra operations using the SymPy library in Python. It outlines how to import SymPy, create matrices, perform basic operations like addition and multiplication, find eigenvalues and eigenvectors, decompose matrices, and solve systems of linear equations. Useful functions are listed for indexing matrices, performing row operations, working with vectors, and analyzing vector spaces.

Uploaded by

Kimondo King
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
137 views

Linear Algebra Using Sympy Cheat Sheet: by Via

This document provides a cheat sheet for performing linear algebra operations using the SymPy library in Python. It outlines how to import SymPy, create matrices, perform basic operations like addition and multiplication, find eigenvalues and eigenvectors, decompose matrices, and solve systems of linear equations. Useful functions are listed for indexing matrices, performing row operations, working with vectors, and analyzing vector spaces.

Uploaded by

Kimondo King
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Linear Algebra Using SymPy Cheat Sheet

by royqh1979 via cheatography.com/87753/cs/20231/

Import SymPy Basic opertaions Eigenv​alues amd Eigenv​ectors

import sympy as sp Sum A+B Find the eigenv​alues M.eige​‐


Substr​action A-B nvals()
Matrix Creation Find the eignev​alues and the M.eige​nve​‐
Matrix Multiply A*B
normal Matrix sp.M​atr​ix​([​[1,​2],​‐ corres​ponding eigenspace cts()
Scalar Multiply 5*A
[3,4]]) Diagon​alize a matrix P, D =
Elemen​twise sp.mat​rix​_mu​lti​ply​_el​eme​‐
Matrix with all zeros sp.z​ero​s​(4,5) M.diag​ona​‐
product ntw​ise​(A,B)
lize()
Matrix with all ones sp.o​nes​ (4,5)
Transpose A.T
test if the matrix is diagon​ali​‐ M.is_d​iag​‐
Square matrix with all sp.z​ero​s(5)
Determ​inant A.det()
zable ona​lizable
zeros
Inverse A.inv()
Calculate Jordan From P, J =
Square matrix with all sp.o​nes​ (5)
Condition A.cond​iti​on_​num​ber() M.jord​an_​‐
ones
Number form()
Identity matrix sp.e​yes​(5)
Row count A.rows
Diagonal Matrix sp.d​iag​ (​‐ Decomp​osition
Column count A.cols
1,2​,3,4)
Trace A.trace() LU Decomp​osi​tio​‐ P,L,U=​A.L​Ude​com​‐
Generate element with sp.M​atr​ix​(2​,3,​‐
n(P​A=LU) pos​ition()
func(i,j) func)
Elementary Row Operations QR Decomp​osition Q,R=A.Q​Rd​eco​mpo​‐
sit​ion()
Matrix Modifi​cation Replac​‐ m.row_​op(i, lambda ele,co​l:e​‐
ement le+​m.r​ow(​j)[​col]*c)
Delete the i-th row M.row_​del(i) Vector Operations
Interc​‐ M.row_​swa​p(i,j)
Delete the j-th column M.col_​del(j)
hange Create a column vector v=sp.M​atr​ix(​[1,​‐
Row join M1 and M2 M1.row​_jo​in(M2) 2,3])
Scaling m.row_​op(​i,​la​mbda ele,co​l:e​‐
Column join M1 and M2 M1.col​_jo​in(M2) dot product v1.dot(v2)
le*c)
cross product v1.cro​ss(v2)
Indexi​ng(​Sli​cing)
Linear Equations length of the vector v.norm()
get the element in M at (i,j) M[i,j]
Echelon From M.eche​lon​_form() normalize of vector v.norm​alize()
get the i-th row in M M.row(i)
Reduced Echelon M.rref() the projection of v1 on v1.pro​jec​t(v2)
get the i-th row in M M[i,:] Form v2
get the j-th column in M M.col(j) Solve AX=B (B x,free​var​s=A.ga​uss​‐ Gram-S​chmidt orthog​‐ sp.Gra​mSc​hmi​‐
get the j-th column in M M[:,j] can be a matrix) _jo​rda​n_s​olve(B) onalize dt(​[v1​,v2​,v3])
get the i-th and the k-th rows M[[i,k],:] least-​square fit A.solv​e_l​eas​t_s​qua​‐ Gram-S​chmidt orthog​‐ sp.Gra​mSc​hmi​‐
Ax=b res(b) onalize with normal​‐ dt(​‐
get the j-th and the k-th columns M[:,[j,k]]
solve Ax=b A.solve(b) ization [v1​,v2​,v3​],True)
get rows from i to k M[i:k,:]
Singular values M.sing​lul​ar_​val​‐
get columns from j to k M[:,j:k]
Vector Space ues()
get sub-matrix (row i to k,col j to M[i:k,j:l]
Basis of column space M.colu​mns​pace()
l)
Block Matrix
Basis of null space M.null​space()
Note: All indices start from 0
Create a matrix by M=sp.M​atr​ix(​[[A​,B]​,
Basis of row space M.rows​pace()
block [C​,D]])
Rank M.rank()

By royqh1979 Published 8th August, 2019. Sponsored by Readable.com


cheatography.com/royqh1979/ Last updated 24th August, 2019. Measure your website readability!
Page 1 of 2. https://readable.com
Linear Algebra Using SymPy Cheat Sheet
by royqh1979 via cheatography.com/87753/cs/20231/

Useful Links

SymPy Documentation
SymPy Tutorial

By royqh1979 Published 8th August, 2019. Sponsored by Readable.com


cheatography.com/royqh1979/ Last updated 24th August, 2019. Measure your website readability!
Page 2 of 2. https://readable.com

You might also like