title: Efficient way to create a diagonal sparse matrix
body: <p>I have the following code in Python using Numpy:</p>
  
  <pre><code>p = np.diag(1.0 / np.array(x))
  </code></pre>
  
  <p>How can I transform it to get the sparse matrix <code>p2</code> with the same values as <code>p</code> without creating <code>p</code> first?</p>