Scipy Cheat Sheet Python For Data Science: Linear Algebra
Scipy Cheat Sheet Python For Data Science: Linear Algebra
Scipy Cheat Sheet Python For Data Science: Linear Algebra
>>> A = np.matrix(np.random.random((2,2)))
Division
>>> 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)
> Interacting With NumPy Also see NumPy >>> linalg.norm(A,1) #L1 norm (max column sum)
>>> a = np.array([1,2,3])
>>> np.linalg.matrix_rank(C) #Matrix rank >>> linalg.cosm(D) Matrix cosine
>>>
>>>
b.flatten() #Flatten the array
>>>
>>>
F = np.eye(3, k=1) #Create a 2X2 identity matrix
>>> p = poly1d([3,4,5]) #Create a polynomial object Sparse Matrix Routines Singular Value Decomposition
>>> U,s,Vh = linalg.svd(B) #Singular Value Decomposition (SVD)
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
>>>
>>>
np.real_if_close(c,tol=1000) #Return a real array if complex parts close to 0
>>>
>>>
g = np.linspace(0,np.pi,num=5) #Create an array of evenly spaced values(number of samples)
g [3:] += np.pi
> Asking For Help Learn Data Skills Online at
>>>
>>>
np.unwrap(g) #Unwrap
www.DataCamp.com
>>> np.select([c<4],[c*2]) #Return values from a list of arrays depending on
conditions
>>> help(scipy.linalg.diagsvd)