title: How do you store explicit 0 values in a scipy sparse lil_matrix?
body: <p>scipy.sparse.lil_matrix objects do not seem to store explicitly-set 0 values. Other sparse matrices, such as the csr_matrix, do.</p>
  
  <p>Consider the following example:</p>
  
  <pre><code>In [1]: from scipy.sparse import lil_matrix
  
  In [2]: import numpy as np
  
  In [3]: x = lil_matrix((5, 5), dtype=np.float32)
  
  In [4]: x[3, 3] = 0
  
  In [5]: x
  Out[5]:
  &lt;5x5 sparse matrix of type '&lt;class 'numpy.float32'&gt;'
          with 0 stored elements in LInked List format&gt;
  </code></pre>
  
  <p>This is bad because sometimes there will be a 0 distance between elements of a graph (e.g., duplicates of a datapoint). If I pass a lil_matrix to, e.g., scipy.sparse.csgraph.connected_components, it will detect the incorrect number of connected components because the explicit 0 is converted back to "sparsity" and therefore treated as infinite distance.</p>
  
  <p>I cannot use csr_matrix because it is very inefficient to assign elements to it. However, it will store explicitly-set 0 values unlike lil_matrix. Replace lil_matrix with csr_matrix in the above code and the output changes to:</p>
  
  <pre><code>&lt;5x5 sparse matrix of type '&lt;class 'numpy.float32'&gt;'
          with 1 stored elements in Compressed Sparse Row format&gt;
  </code></pre>
  
  <p>Does anyone know how to store explicit 0 values in lil_matrix objects?</p>
  
  <p>Thanks.</p>