SciPy Cheat Sheet
SciPy Cheat Sheet
>>> A = np.matrix(np.random.random((2,2)))
vs
Di i ion
>>> B = np.asmatrix(b)
>>> np.divide(A,D) #Division
>>> C = np.mat(np.random.random((10,5)))
NumPy extension of Python. >>> np.trace(A) #Trace >>> linalg.expm2(A) #Matrix exponential (Taylor Series)
>>> a = np.array([1,2,3])
>>> np.linalg.matrix_rank(C) #Matrix rank >>> linalg.cosm(D) Matrix cosine
Decompositions
>>> np.hstack((b,c)) #Stack arrays horizontally (column-wise)
>>> G = np.mat(np.identity(2)) #Create a 2x2 identity matrix
Polynomials >>> sparse.isspmatrix_csc(A) #Identify sparse matrix >>> v[:,1] #Second eigenvector
Vectorizing Functions >>> sparse.linalg.inv(I) #Inverse >>> Sig = linalg.diagsvd(s,M,N) #Construct sigma matrix in SVD
Norm LU Decomposition
>>> def myfunc(a): if a < 0:
>>> P,L,U = linalg.lu(C) #LU Decomposition
return a*2
>>> sparse.linalg.norm(I) #Norm
else:
Solving linear problems
return a/2
>>>
>>>
>>>
g = np.linspace(0,np.pi,num=5) #Create an array of evenly spaced values(number of samples)
g [3:] += np.pi
np.unwrap(g) #Unwrap