double[][] data_array
SimpleMatrix dataMatrix = new SimpleMatrix(data_array);
SimpleMatrix omegaMatrix = new SimpleMatrix(omega);
SimpleMatrix cMatrix = dataMatrix.mult(omegaMatrix);
System.out.println("Multiplied");
cMatrix.print();
我正在使用 EJML
库进行矩阵运算。
1.How to convert a simple matrix back to double[][].
上面的结果是一个1乘1的矩阵。
2. Can we store this value in a double variable?
最佳答案
数据不一定存储为 double[][]
数组。事实上,它存储为 double[]
数组。可以得到内部的DenseMatrix64F
,从这里可以得到double[]
数组:
double data[] = cMatrix.getMatrix().getData();
此数组以行-major 格式存储数据。
为了将其存储在单个值中,您可以调用
double singleValue = cMatrix.getMatrix().getData()[0];
编辑:我认为这是在评论中要求的,但我不确定....:
private static double[][] toArray(DenseMatrix64f matrix)
{
double array[][] = new double[matrix.getNumRows()][matrix.getNumCols()];
for (int r=0; r<matrix.getNumRows(); r++)
{
for (int c=0; c<matrix.getNumCols(); c++)
{
array[r][c] = matrix.get(r,c);
}
}
return array;
}
关于java - 使用 EJML 的矩阵乘法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22453229/