简体   繁体   中英

Math.NET Numerics - Matrix<double> from an array of doubles

Assuming I have:

double[] someArray = new [] { 11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34, 41, 42, 43, 44 };

Is there any out of the box way of creating a 4x4 matrix out of this array without having to split it into 4 arrays myself?

I know it is simple to do this, but I'm exploring how much is ready out of the box.

EDIT

Sorry for not being clear (thought title was):

What I'm wondering is if there is out of the box functionality with the Matrix builder in Math.NET Numerics. Something like:

Matrix<double> someMatrix = DenseMatrix.OfArray(columns: 4, rows: 4, data: someArray);

From looking at the documentation , you could use the constructor directly, or the function OfColumnMajor(int rows, int columns, IEnumerable<double> columnMajor) , if your data is in column-major order.

The code would look like this:

//Using the constructor
Matrix<double> someMatrix = new DenseMatrix(4, 4, someArray)

//Using the static function
Matrix<double> someMatrix = DenseMatrix.OfColumnMajor(4, 4, someArray);

If your data is in row-major order, you could split into arrays and use one of the OfRows function, or use the constructor and transpose the matrix, as suggested by Christoph.

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