How to print JAMA matrix columns?

I am using the JAMA.matrix package. How can I print matrix columns

+3
source share
3 answers

You can call the getArray () method on the matrix to get a double [] [] representing the elements.
You can then go through this array to display any columns / rows / elements you want.

See the API for more details .

0
source

The easiest way is probably to transpose the matrix and then print each row. Taking an example from the API :

double[][] vals = {{1.,2.,3},{4.,5.,6.},{7.,8.,10.}};
Matrix a = new Matrix(vals);
Matrix aTransposed = a.transpose();
double[][] valsTransposed = aTransposed.getArray();

// now loop through the rows of valsTransposed to print
for(int i = 0; i < valsTransposed.length; i++) {
    for(int j = 0; j < valsTransposed[i].length; j++) {        
        System.out.print( " " + valsTransposed[i][j] );
    }
}

duffymo , . , . ( ), .

+1
public static String strung(Matrix m) {
    StringBuffer sb = new StringBuffer();
    for (int r = 0; r < m.getRowDimension(); ++ r) {
        for (int c = 0; c < m.getColumnDimension(); ++c)
            sb.append(m.get(r, c)).append("\t");
        sb.append("\n");
    }
    return sb.toString();
}
0
source

Source: https://habr.com/ru/post/1704572/


All Articles