transpose double[][] matrix with a java function?

后端 未结 6 1573
夕颜
夕颜 2020-12-03 05:55

Do anybody have a function with which I can transpose a Matrix in Java which has the following form:

double[][]

I have function like this:<

6条回答
  •  猫巷女王i
    2020-12-03 06:36

    Here is the method

    public static double[][] transpose(double arr[][]){
        int m = arr.length;
        int n = arr[0].length;
        double ret[][] = new double[n][m];
    
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                ret[j][i] = arr[i][j];
            }
        }
    
        return ret;
    }
    

提交回复
热议问题