Java tutorial
//package com.java2s; public class Main { private static float[][] tempMat; public static void transposeMatrix(float[][] origMat, boolean scaleOrNo) { //float [][] outMat = new float[origMat.length][origMat.length]; for (int i = 0; i < origMat.length; i++) { System.arraycopy(origMat[i], 0, tempMat[i], 0, origMat.length); } for (int row = 0; row < origMat.length; row++) { for (int col = 0; col < origMat.length; col++) { if (scaleOrNo) { origMat[col][row] = tempMat[row][col] / (float) origMat.length; } else { origMat[col][row] = tempMat[row][col]; } } } return; } }