There are methods to convert one sparse type into another or into an array:
AS.toarray # converts sparse formats to a numpy array AS.tocsr AS.tocsc AS.tolil
The type of a sparse matrix can be inspected by the methods issparse, isspmatrix_lil, isspmatrix_csr, and isspmatrix_csc.
Elementwise operations +, *, /, and ** on sparse matrices are defined as for NumPy arrays. Regardless of the sparse matrix format of the operands, the result is always csr_matrix. Applying elementwise operating functions to sparse matrices requires first transforming them to either CSR or CSC format and applying the functions to their data attribute, as demonstrated by the next example.
The elementwise sine of a sparse matrix can be defined by an operation on its data attribute:
import scipy.sparse as sp def sparse_sin(A): if not (sp.isspmatrix_csr(A) or sp.isspmatrix_csc(A)): A = A.tocsr() A.data = sin(A.data...