Java Matrix Transpose transpose(double[][] arr)

Here you can find the source of transpose(double[][] arr)

Description

transpose

License

Open Source License

Declaration

public static double[][] transpose(double[][] arr) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static double[][] transpose(double[][] arr) {
        double[][] newArr = new double[arr[0].length][arr.length];
        for (int x = 0; x < arr.length; x++)
            for (int y = 0; y < arr[x].length; y++)
                newArr[y][x] = arr[x][y];
        return newArr;
    }//  w ww. ja  v  a2 s.c o  m

    public static Double[][] transpose(Double[][] arr) {
        Double[][] newArr = new Double[arr[0].length][arr.length];
        for (int x = 0; x < arr.length; x++)
            for (int y = 0; y < arr[x].length; y++)
                newArr[y][x] = arr[x][y];
        return newArr;
    }

    public static int[][] transpose(int[][] arr) {
        int[][] newArr = new int[arr[0].length][arr.length];
        for (int x = 0; x < arr.length; x++)
            for (int y = 0; y < arr[x].length; y++)
                newArr[y][x] = arr[x][y];
        return newArr;
    }

    public static Integer[][] transpose(Integer[][] arr) {
        Integer[][] newArr = new Integer[arr[0].length][arr.length];
        for (int x = 0; x < arr.length; x++)
            for (int y = 0; y < arr[x].length; y++)
                newArr[y][x] = arr[x][y];
        return newArr;
    }

    public static String[][] transpose(String[][] arr) {
        String[][] newArr = new String[arr[0].length][arr.length];
        for (int x = 0; x < arr.length; x++)
            for (int y = 0; y < arr[x].length; y++)
                newArr[y][x] = arr[x][y];
        return newArr;
    }
}

Related

  1. transpose(boolean[][] toBeTransposed)
  2. transpose(byte[][] d)
  3. transpose(double array[], int W, int H, int D)
  4. transpose(double[] m)
  5. transpose(double[][] A)
  6. transpose(double[][] ary)
  7. transpose(double[][] in)
  8. transpose(double[][] matrix)
  9. transpose(double[][] matrix)