2

I created matrix by np.zeros(), and tested it with sp.issparse(). Why I get false even the matrix is zero (or in case of mostly zero matrix as well)?

Jan
  • 1,389
  • 4
  • 17
  • 43

1 Answers1

3

A sparse matrix has a different memory representation: it is not the cells being zero that matters but the fact that the cells are allocated in memory.

np.zeros() allocates all fields of the array in memory, even those being zero, while a sparse matrix does not.

See here for how to convert from a numpy matrix/array to a sparse matrix.

akoeltringer
  • 1,671
  • 3
  • 19
  • 34