You can use methods like getrow(), getcol(), and tolil() to efficiently manipulate sparse matrices.
Example Code: Extracting a Row and Converting to LIL Format
from scipy.sparse import csr_matrix, lil_matrix
# Create a sparse matrix
A = csr_matrix([[1, 0, 2],
[0, 0, 3],
[4, 0, 5]])
# Extract the second row as a sparse matrix
row = A.getrow(1)
print(row.toarray())
# Convert the sparse matrix to LIL format
A_lil = A.tolil()
A_lil[1, 1] = 6 # Modify a single element
print(A_lil.toarray())