title: Constructing a diagonal matrix from vector of integers: function eigen
body: <p>I have a vector of integers and I want to construct a diagonal matrix with vectos's element as diagonal entries of the matrix. For example: if vector is <code>1 2 3</code> the diagonal matrix would be:</p>
  
  <pre><code>1 0 0
  0 2 0
  0 0 3
  </code></pre>
  
  <p>The naive way to do it would be just iterate over it and set elements one by one. Is there no other direct way to do this in <code>eigen</code>. Also after constructing the diagonal I want to calculate the inverse(which is just reversing the diagonal entries) but there does not seem to be a way to do this too(directly, which would be optimized way too) in the library itself.</p>
  
  <p>I have looked up the documentation of <a href="http://eigen.tuxfamily.org/dox/classEigen_1_1DiagonalMatrix.html#a47affd1a10b589811fc4828c1a2e0c6d" rel="noreferrer">diagonal matrices</a> in <code>eigen</code> library but it seems like that there is no way .If I have missed something obvious while reading the documentation please point out.</p>
  
  <p>Any help appreciated.</p>