title: Permute Columns of Matrix in Eigen
body: <p>I read this answer <a href="https://stackoverflow.com/questions/15858569/randomly-permute-rows-columns-of-a-matrix-with-eigen">Randomly permute rows/columns of a matrix with eigen</a></p>
  
  <p>But they initialize the permutation matrix as the identity matrix and do a random shuffle. I'm wondering how I can initialize the matrix to a specific permutation. </p>
  
  <p>For example, if I have a vector of integers where each (index, value) pair means I want to move column "index" to column "value" how can I do this?</p>
  
  <pre><code>Eigen::MatrixXi M = Eigen::MatrixXi::Random(3,3);
  std::vector&lt;int&gt; my_perm = {1,2,0};
  some_function to return Matrix [M.col(1), M.col(2), M.col(0)]
  </code></pre>
  
  <p><strong>EDIT: dtell kindly answered my original question below.</strong></p>
  
  <p><strong>ADDITIONAL INFO:</strong></p>
  
  <p>For anyone else looking at this -- if you want to permute a matrix with a vector of unknown (at compile time) quanties, you can do the following:</p>
  
  <pre><code>Eigen::VectorXi indices(A.cols());
  for(long i = 0; i &lt; indices.size(); ++i) {
      indices[i] = vector_of_indices[i];
  }
  Eigen::PermutationMatrix&lt;Eigen::Dynamic, Eigen::Dynamic&gt; perm;
  perm.indices() = indices;
  Eigen::MatrixXd A_permute = A * perm; \\ permute the columns
  </code></pre>