Java Matrix Transpose transposeSquareMatrix(T[][] matrixT)

Here you can find the source of transposeSquareMatrix(T[][] matrixT)

Description

transpose Square Matrix

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
    public static <T> T[][] transposeSquareMatrix(T[][] matrixT) 

Method Source Code

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

public class Main {
    @SuppressWarnings("unchecked")
    public static <T> T[][] transposeSquareMatrix(T[][] matrixT) {
        Object[][] matrix = new Object[matrixT.length][matrixT.length];
        int matrixSize = matrixT.length;
        for (int i = 0; i < matrixSize; i++) {
            for (int j = 0; j < matrixSize; j++) {
                matrix[i][j] = (Object) matrixT[j][i];
            }//from  w ww  . ja  v  a  2  s.  c  o  m
        }
        return (T[][]) matrix;
    }

    public static int[][] transposeSquareMatrix(int[][] matrixT) {
        int[][] matrix = new int[matrixT.length][matrixT.length];
        int matrixSize = matrixT.length;
        for (int i = 0; i < matrixSize; i++) {
            for (int j = 0; j < matrixSize; j++) {
                matrix[i][j] = matrixT[j][i];
            }
        }
        return matrix;
    }
}

Related

  1. transposeMatrix(double[][] m)
  2. transposeMatrix(final float[] msrc, final int msrc_offset, final float[] mres, final int mres_offset)
  3. transposeMatrix3x3(float[] result, float[] m)
  4. transposematrixmultiply(final double[][] A, final double[] b)
  5. transposeQuad(final double[][] src, int n)
  6. transposeValue(long[] valSet, int DEPTH)