I'm trying to use the isspmatrix (alias issparse) function.
Constructed a sparse matrix using csr_matrix, tried converting it to a standard python list of lists, then a flat 1-D list (the last two, just to see if it was a formatting thing).
In each case, the function returns false. Can anyone see why?
import numpy as np
from scipy.sparse import csr_matrix, isspmatrix, issparse
indptr = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
indices = np.array([1, 3, 4, 0, 2, 5, 0, 1, 2, 3, 5])
data = np.array([9, 4, 8, 5, 1, 7, 1, 5, 3, 5, 9])
sparse_array = csr_matrix((data, indices, indptr), shape=(11, 6)).toarray()
print(sparse_array)
print(isspmatrix(sparse_array))
sparse_list = np.array(sparse_array).tolist()
print(sparse_list)
print(isspmatrix(sparse_list))
sparse_matrix = []
for l in sparse_list:
for i in l:
sparse_matrix.append(i)
print(sparse_matrix)
print(isspmatrix(sparse_matrix))