Re: [eigen] How to convert a Matrix into (big) column vector |

[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]

On 22.01.2012 12:16, Helmut Jarausch wrote:

how can I cheaply convert a Matrix to a big column vector containing
all the columns of the Matrix stacked one on top of the other
(assuming the Matrix is in column order, of course)

`Assuming the matrix is in column order and has no strides, you can take
``the .data() pointer and generate a Map using it.
`
MatrixXd mat;
VectorXd::Map(mat.data(), mat.rows()*mat.cols());
I guess, you can even use an aligned map for that.

`Alternatively, if you just want to access sole elements, you can simply
``use mat(i); to access the i^th element (similar as in Matlab).
`

`Actually, instead of the last, I would prefer if there was a method
``..asVector() which generates a Map as above (and automatically decides if
``the data is aligned).
``Question would be, if .asVector() can also be implemented for
``Block-types and strided maps somehow.
`
Christoph
--
----------------------------------------------
Dipl.-Inf. Christoph Hertzberg
Cartesium 0.051
Universität Bremen
Enrique-Schmidt-Straße 5
28359 Bremen
Tel: (+49) 421-218-64252
----------------------------------------------