joh*_*son 3 c# arrays matrix mathnet-numerics
假设我有:
double[] someArray = new [] { 11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34, 41, 42, 43, 44 };
是否有任何开箱即用的方法可以从此数组中创建 4x4 矩阵,而不必自己将其拆分为 4 个数组?
我知道这样做很简单,但我正在探索开箱即用的准备情况。
编辑
抱歉不清楚(认为标题是):
我想知道的是 Math.NET Numerics 中的矩阵生成器是否具有开箱即用的功能。就像是:
Matrix<double> someMatrix = DenseMatrix.OfArray(columns: 4, rows: 4, data: someArray);
通过查看文档,您可以直接使用构造函数或函数OfColumnMajor(int rows, int columns, IEnumerable<double> columnMajor)
,如果您的数据是列优先顺序。
代码如下所示:
//Using the constructor
Matrix<double> someMatrix = new DenseMatrix(4, 4, someArray)
//Using the static function
Matrix<double> someMatrix = DenseMatrix.OfColumnMajor(4, 4, someArray);
Run Code Online (Sandbox Code Playgroud)
如果您的数据按行优先顺序排列,您可以OfRows
按照 Christoph 的建议拆分为数组并使用其中一个函数,或者使用构造函数并转置矩阵。