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?
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With