Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access a column of a matrix as a vector in Eigen

Tags:

c++

eigen

How can I access a single vector from a matrix?

For example: Is there a way to extract a vector using something like A(i) for a matrix Eigen::MatrixXf A(10,10) that returns an Eigen::VectorXf A(10)?

like image 476
R.J. Avatar asked Mar 01 '12 08:03

R.J.


People also ask

Is Eigen vector a column vector?

As mentioned above, in Eigen, vectors are just a special case of matrices, with either 1 row or 1 column. The case where they have 1 column is the most common; such vectors are called column-vectors, often abbreviated as just vectors.

Are the columns of a matrix vectors?

Matrix is a 3 × 1 matrix. It has rows and column. Thus, it is a column vector.

Is Eigen row or column major?

The default in Eigen is column-major.

How do you get a column from a matrix in R?

To get a specific column of a matrix, specify the column number preceded by a comma, in square brackets, after the matrix variable name. This expression returns the required row as a vector.


1 Answers

Found in the documentation :/ The way to access a single column is .col(i), and similarly for row, its .row(i). Also of interest is .block<>.

like image 164
R.J. Avatar answered Sep 19 '22 14:09

R.J.