Sep-18-2021, 09:19 PM
# Who solve sparse matrix with A sparce: A.x = f
# 2x + 3y + 0 = 6
# 0 + 0 + 2z = 4
# 4x + 0 + 1z = 2
#This is an example of sparse matrix above
# So I'm going to name rows, columns and data
import numpy as np
from scipy.sparse import bsr_matrix
row_bsr = np.array([0, 0, 1, 2, 2])
col_bsr = np.array([0, 1, 2, 0, 2])
data_bsr = np.array([2, 3, 2, 4, 1])
A = bsr_matrix((data_bsr, (row_bsr, col_bsr)), shape = (3,3) )
print(A)
# how to declare "b" in this case
# if I print A result OK
print(A)
# but I need x = A⁻1 f
# how do i proceed to extract the x
#=> This is my question because the scipy documentation doesn't show how to solve this.
# have many way:
# 1. bsr_matrix: Block Sparse Row matrix
# 2. coo_matrix: COOrdinate format matrix
# 4. csc_matrix: Compressed Sparce Column matrix
# 5. dia_matrix: Sparce matrix with DAgoal storage
# 6. dok_matrix: Dictionary Of Key based sparce matrix
# 7. lil_matrixÇ Row-based linked list sparse matrix.
# How to solve this matrix to extract the x.
# Common array resolution I can solve in Python but sparse
# arrays can't find the proper codes. The example above is
#pretty simple but my problem is 29x29 with a lot of zeros
#in A and only two values in f.
# 2x + 3y + 0 = 6
# 0 + 0 + 2z = 4
# 4x + 0 + 1z = 2
#This is an example of sparse matrix above
# So I'm going to name rows, columns and data
import numpy as np
from scipy.sparse import bsr_matrix
row_bsr = np.array([0, 0, 1, 2, 2])
col_bsr = np.array([0, 1, 2, 0, 2])
data_bsr = np.array([2, 3, 2, 4, 1])
A = bsr_matrix((data_bsr, (row_bsr, col_bsr)), shape = (3,3) )
print(A)
# how to declare "b" in this case
# if I print A result OK
print(A)
# but I need x = A⁻1 f
# how do i proceed to extract the x
#=> This is my question because the scipy documentation doesn't show how to solve this.
# have many way:
# 1. bsr_matrix: Block Sparse Row matrix
# 2. coo_matrix: COOrdinate format matrix
# 4. csc_matrix: Compressed Sparce Column matrix
# 5. dia_matrix: Sparce matrix with DAgoal storage
# 6. dok_matrix: Dictionary Of Key based sparce matrix
# 7. lil_matrixÇ Row-based linked list sparse matrix.
# How to solve this matrix to extract the x.
# Common array resolution I can solve in Python but sparse
# arrays can't find the proper codes. The example above is
#pretty simple but my problem is 29x29 with a lot of zeros
#in A and only two values in f.