In [1]:
import numpy as np
from scipy.sparse import csr_matrix, csc_matrix
from scipy.sparse.linalg import inv, eigs
In [2]:
l = [[2, 5],
[1, 3]]
In [3]:
csr = csr_matrix(l)
csc = csc_matrix(l)
In [4]:
# csr_inv = linalg.inv(csr)
# SparseEfficiencyWarning: splu requires CSC matrix format
# SparseEfficiencyWarning: spsolve is more efficient when sparse b is in the CSC matrix format
In [5]:
csc_inv = inv(csc)
print(csc_inv)
In [6]:
print(type(csc_inv))
In [7]:
print(csc_inv.toarray())
In [8]:
l = [[1, 1, 2],
[0, 2, -1],
[0, 0, 3]]
In [9]:
w, v = np.linalg.eig(l)
In [10]:
print(w)
In [11]:
print(v)
In [12]:
csr_f = csr_matrix(l, dtype=float)
csr_i = csc_matrix(l, dtype=int)
In [13]:
w, v = eigs(csr_f, k=1)
In [14]:
print(w)
In [15]:
print(v)
In [16]:
# w, v = eigs(csr_f, k=2)
# TypeError: Cannot use scipy.linalg.eig for sparse A with k >= N - 1. Use scipy.linalg.eig(A.toarray()) or reduce k.
In [17]:
# w, v = eigs(csr_i, k=1)
# ValueError: matrix type must be 'f', 'd', 'F', or 'D'