title: Create sparse DIA matrix, and then change columns
body: <p>I have two vectors <code>t</code>, and <code>delta</code> - both of length <code>n</code>. I want to create a sparse <code>DIA</code> matrix <code>A</code> with that vector, and then adjust the columns: For all <code>i</code>, I want to move the <code>ith</code> entry in <code>A</code> by <code>delta[i]</code> columns to the left.</p>
  
  <p>An easy way to control columns is in the <code>COO</code>  format. Here's what I thought would work:</p>
  
  <pre><code>from scipy.sparse import diags
  A = diags([t], offsets=[-1]).tocoo()
  A.col = A.col - delta
  </code></pre>
  
  <p>However, in my example <code>A.nnz == len(A.col)</code> is only <code>216</code>, while the length of <code>t</code> and <code>delta</code> is <code>239</code>. I don't understand how that happened, given that <code>nnz</code> stores <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.coo_matrix.html" rel="nofollow noreferrer">"Number of stored values, including explicit zeros."</a>. </p>
  
  <p>How can I tackle this problem? Here's my example data:</p>
  
  <pre><code>from numpy import np
  t = np.array([ 2.655,  2.655,  2.655,  2.655,  2.655,  2.655,  2.655,  2.655,
          2.655,  2.655,  2.655,  2.655,  2.655,  2.655,  2.655,  2.655,
          2.655,  2.655,  2.655,  2.655,  2.655,  2.655,  2.655,  2.155,
          2.155,  2.155,  2.155,  2.155,  2.155,  2.155,  2.155,  2.155,
          2.155,  2.155,  2.155,  2.155,  2.155,  2.155,  2.155,  2.155,
          2.155,  2.155,  2.155,  2.155,  2.155,  2.155,  2.155,  1.655,
          1.655,  1.655,  1.655,  1.655,  1.655,  1.655,  1.655,  1.655,
          1.655,  1.655,  1.655,  1.655,  1.655,  1.655,  1.655,  1.655,
          1.655,  1.655,  1.655,  1.655,  1.655,  1.655,  1.655,  1.155,
          1.155,  1.155,  1.155,  1.155,  1.155,  1.155,  1.155,  1.155,
          1.155,  1.155,  1.155,  1.155,  1.155,  1.155,  1.155,  1.155,
          1.155,  1.155,  1.155,  1.155,  1.155,  1.155,  1.155,  0.655,
          0.655,  0.655,  0.655,  0.655,  0.655,  0.655,  0.655,  0.655,
          0.655,  0.655,  0.655,  0.655,  0.655,  0.655,  0.655,  0.655,
          0.655,  0.655,  0.655,  0.655,  0.655,  0.655,  0.655,  0.405,
          0.405,  0.405,  0.405,  0.405,  0.405,  0.405,  0.405,  0.405,
          0.405,  0.405,  0.405,  0.405,  0.405,  0.405,  0.405,  0.405,
          0.405,  0.405,  0.405,  0.405,  0.405,  0.405,  0.405,  0.405,
          0.405,  0.405,  0.405,  0.405,  0.405,  0.405,  0.405,  0.405,
          0.405,  0.405,  0.405,  0.405,  0.405,  0.405,  0.405,  0.405,
          0.405,  0.405,  0.405,  0.405,  0.405,  0.405,  0.405,  0.405,
          0.405,  0.405,  0.405,  0.405,  0.405,  0.405,  0.405,  0.405,
          0.405,  0.405,  0.405,  0.405,  0.405,  0.405,  0.405,  0.405,
          0.405,  0.405,  0.405,  0.405,  0.405,  0.405,  0.405,  0.405,
          0.405,  0.405,  0.405,  0.405,  0.405,  0.405,  0.405,  0.405,
          0.405,  0.405,  0.405,  0.405,  0.405,  0.405,  0.405,  0.405,
          0.405,  0.405,  0.405,  0.405,  0.405,  0.405,  0.405,  0.   ,
          0.   ,  0.   ,  0.   ,  0.   ,  0.   ,  0.   ,  0.   ,  0.   ,
          0.   ,  0.   ,  0.   ,  0.   ,  0.   ,  0.   ,  0.   ,  0.   ,
          0.   ,  0.   ,  0.   ,  0.   ,  0.   ,  0.   ,  0.   ])
  delta = np.array([0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5,
     5, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5,
     5, 5, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5,
     5, 5, 5, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4,
     5, 5, 5, 5, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4,
     4, 5, 5, 5, 5, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4,
     4, 4, 5, 5, 5, 5, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4,
     4, 4, 4, 5, 5, 5, 5, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3,
     4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3,
     3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0, 0, 1, 1, 1, 1, 2, 0, 2, 2, 3, 2,
     1, 3, 4, 3, 0, 3, 5, 4, 1, 0])
  </code></pre>