Java Matrix Transpose transpose(Object[][] matrix)

Here you can find the source of transpose(Object[][] matrix)

Description

Transpoe a matriz (Transforma linhas em colunas e vice versa)

License

Open Source License

Parameter

Parameter Description
matrix Object[][] Matriz a ser transposta

Return

Object[][] Matriz transposta

Declaration

public static Object[][] transpose(Object[][] matrix) 

Method Source Code

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

public class Main {
    /**/*ww w.  j  a  v  a 2  s  .  co m*/
     * Transpoe a matriz (Transforma linhas em colunas e vice versa)
     *
     * @param matrix {@code Object[][]} Matriz a ser transposta
     * @return {@code Object[][]} Matriz transposta
     */
    public static Object[][] transpose(Object[][] matrix) {
        Object[][] transposed = new Object[matrix[0].length][matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[i].length; j++) {
                transposed[j][i] = matrix[i][j];
            }
        }
        return transposed;
    }

    /**
     * Transpoe a matriz (Transforma linhas em colunas e vice versa)
     *
     * @param matrix {@code Integer[][]} Matriz a ser transposta
     * @return {@code Integer[][]} Matriz transposta
     */
    private Integer[][] transpose(Integer[][] matrix) {
        Integer[][] transposed = new Integer[matrix[0].length][matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[i].length; j++) {
                transposed[j][i] = matrix[i][j];
            }
        }
        return transposed;
    }
}

Related

  1. transpose(int[][] input)
  2. transpose(int[][] M)
  3. transpose(int[][] matrix)
  4. transpose(int[][][] as, int A, int[][][] ast)
  5. transpose(long[] a, double offset)
  6. transpose(Object[][] matrix)
  7. transpose2d(Object[][] array)
  8. transpose2DArray(Double[][] data)
  9. transpose3x3Matrix(float[][] m)