Java Matrix Transpose transpose2DArray(Double[][] data)

Here you can find the source of transpose2DArray(Double[][] data)

Description

Transpose a 2D array of Double

License

Apache License

Parameter

Parameter Description
data a parameter

Return

the same 2D array but transposed

Declaration

public static Double[][] transpose2DArray(Double[][] data) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*w w w  .j a  v  a 2s. c  o m*/
     * Transpose a 2D array of Double
     *
     * @param data
     * @return the same 2D array but transposed
     */
    public static Double[][] transpose2DArray(Double[][] data) {
        Double[][] transposed = new Double[data[0].length][data.length];
        for (int rowIndex = 0; rowIndex < data.length; rowIndex++) {
            for (int columnIndex = 0; columnIndex < data[0].length; columnIndex++) {
                if (data[rowIndex][columnIndex] != null) {
                    transposed[columnIndex][rowIndex] = data[rowIndex][columnIndex];
                }
            }
        }
        return transposed;
    }

    /**
     * Transpose a 2D array of double
     *
     * @param data
     * @return the same 2D array but transposed
     */
    public static double[][] transpose2DArray(double[][] data) {
        double[][] transposed = new double[data[0].length][data.length];
        for (int rowIndex = 0; rowIndex < data.length; rowIndex++) {
            for (int columnIndex = 0; columnIndex < data[0].length; columnIndex++) {
                transposed[columnIndex][rowIndex] = data[rowIndex][columnIndex];
            }
        }
        return transposed;
    }
}

Related

  1. transpose(int[][][] as, int A, int[][][] ast)
  2. transpose(long[] a, double offset)
  3. transpose(Object[][] matrix)
  4. transpose(Object[][] matrix)
  5. transpose2d(Object[][] array)
  6. transpose3x3Matrix(float[][] m)
  7. transpose4x4(float m[], float t[])
  8. transpose_image(Object source, int width, int height)
  9. transposeBooleanMatrix(boolean[][] matrix)