title: Eigen C++ Sparse Matrix elementwise product and divide
body: <p>I am trying to convert some methods implemented in Eigen C++ dense matrix class (<code>MatrixXd</code> from <code>&lt;Eigen/Dense&gt;</code>) to methods with Eigen C++ sparse matrix (like <code>SparseMatrix&lt;double&gt;</code> from <code>&lt;Eigen/Sparse&gt;</code>).</p>
  
  <p>Many methods can be directly transformed by simply chance <code>MatrixXd</code> to <code>SparseMatrix&lt;double&gt;</code>. However, some methods cannot be. </p>
  
  <p>One problem I met is to convert the following elementwise dividend into sparse matrix method:</p>
  
  <pre><code>(beta.array() / beta.cwiseAbs().array()).sum()
  </code></pre>
  
  <p>Originally, <code>beta</code> is declared as <code>MatrixXd beta</code>. Now, if I declare <code>beta</code> as <code>SparseMatrix&lt;double&gt; beta</code>, there is no more corresponding <code>array()</code> method to allow me to do the above. </p>
  
  <p>How should I still perform element-wise operations with sparse matrix?</p>
  
  <p>Is there any efficient way that I can convert dense matrix to sparse matrix and vice versa? </p>