Search code examples
javamatrixtransposeoperationcolt

Matrix operations (transpose)


I want to perform matrix operation (for example find the transpose matrix of a given matrix A)

I found some libraries to do so, for example Colt:

http://acs.lbl.gov/software/colt/api/index.html

http://acs.lbl.gov/software/colt/api/cern/colt/matrix/package-summary.html

In the second link is mentioned that if you want to print the transpose, you type:

System.out.println(matrix.viewDice());

However, I don't want to print the transposed matrix. I want to store it in a second matrix, for example B, that would have the appropriate dimensions.

Any ideas?


Solution

  • Have you seen the library Apache Commons Math? e.g.:

    public static void main(String[] args) {
        double[][] data = { { 1, 2, 3 }, { 4, 5, 6 } };
    
        RealMatrix matrix = MatrixUtils.createRealMatrix(data);
    
        RealMatrix transpose = matrix.transpose();
    }