简体   繁体   中英

multiple datatype in a armadillo matrix

I want to create a matrix in Armadillo, which can keep different datatypes in a matrix. For example, I want to have a matrix with three integer columns, a float column, and a column with enumeration value. Is there any solution?

Armadillo matrices store all elements internally as a standard C array of the element datatype. That means all elements must have the same type. This makes sense for armadillo since it is intended to be used for linear algebra and numerical computations, and not as a general container.

For your particular case it is probably better to simply create separated objects. You could, for instance, create a matrix of integers (arma::imat or arma::umat depending if you want sign), a vector of floats (arma::vec) and for the column of enumeration you could use std::vector.

Then you can create a struct with three fields to store these objects (or use a tuple) if you always want to keep them together (to easily pass them as arguments, for instance).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM