Reputation: 6139
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();
I am using EJML
library for matrix operation.
1.How to convert a simple matrix back to double[][].
The above result is a 1 by 1 matrix.
2. Can we store this value in a double variable?
Upvotes: 3
Views: 3886
Reputation: 54639
The data is not necessarily stored as a double[][]
array. In fact, it is stored as a double[]
array. You can obtain the internal DenseMatrix64F
, and from this, you can obtain the double[]
array:
double data[] = cMatrix.getMatrix().getData();
This array stored the data in row-major format.
In order to store this in a single value, you can call
double singleValue = cMatrix.getMatrix().getData()[0];
EDIT: I think this was asked for in the comments, but I'm not sure....:
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;
}
Upvotes: 5