Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide tool to go from 1D to 2D array format #11

Open
lessthanoptimal opened this issue Feb 10, 2016 · 1 comment
Open

Provide tool to go from 1D to 2D array format #11

lessthanoptimal opened this issue Feb 10, 2016 · 1 comment

Comments

@lessthanoptimal
Copy link
Owner

Provide tool to go from 1D to 2D array format

@mroodschild
Copy link

mroodschild commented Jun 3, 2017

Hello!
mayby this can help

public double[][] toArray(SimpleMatrix matrix) {
        double array[][] = new double[matrix.numRows()][matrix.numCols()];
        for (int r = 0; r < matrix.numRows(); r++) {
            array[r] = matrix.extractVector(true, r).getMatrix().getData();
        }
        return array;
}

or at DenseMatrix64F

    public double[][] getData() {
        int count = 0;
        double[][] array = new double[this.numRows][this.numCols];
        for (int i = 0; i < this.numRows; i++) {
            for (int j = 0; j < this.numCols; j++) {
                array[i][j] = this.data[count++];
            }
        }
        return array;
    }

Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants