Java Utililty Methods Matrix Transpose

List of utility methods to do Matrix Transpose

Description

The list of methods to do Matrix Transpose are organized into topic(s).

Method

double[][]matrixTrans_x_diagonalMatrix(double[][] mat, double[] diag)
First transposes a matrix, then multiplies it with another matrix that only contains elements on its diagonal (0 elswhere).
final int m = mat.length;
final int n = mat[0].length;
double[][] res = new double[n][m];
for (int row = 0; row < n; row++) {
    for (int col = 0; col < m; col++) {
        res[row][col] = mat[col][row] * diag[col];
return res;
double[][]matrixTrans_x_diagonalMatrix_x_Matrix(double[][] mat, double[] diag)
First transposes a matrix, then multiplies it with another matrix that only contains elements on its diagonal (0 elswhere), then multiplies it again with the matrix.
final int m = mat.length;
final int n = mat[0].length;
double[][] res = new double[n][n];
double[] row = new double[m];
for (int r = 0; r < n; r++) {
    for (int col = 0; col < m; col++)
        row[col] = mat[col][r] * diag[col];
    for (int j = r; j < n; j++) {
...
double[][]matrixTrans_x_matrix(double[][] mat)
First transposes a matrix, then multiplies it with the original matrix.
final int m = mat.length;
final int n = mat[0].length;
double[][] res = new double[n][n];
for (int r = 0; r < n; r++) {
    for (int c = r; c < n; c++) {
        for (int i = 0; i < m; i++) {
            res[r][c] += mat[i][r] * mat[i][c];
        res[c][r] = res[r][c];
return res;
Object[][]matrixTransform(Object[][] datas)
matrix Transform
if (datas.length == 0 || datas[0].length == 0) {
    return datas;
int column = datas.length;
int row = datas[0].length;
Object[][] newData = new Object[row][column];
for (int i = 0; i < row; i++) {
    Object[] list = new Object[column];
...
Object[][]matrixTranspose(Object[][] matrix)
matrix Transpose
if (null == matrix) {
    return null;
Object[][] matrixT = new Object[matrix[0].length][matrix.length];
for (int i = 0; i < matrix[0].length; i++) {
    for (int j = 0; j < matrix.length; j++) {
        matrixT[i][j] = matrix[j][i];
return matrixT;
boolean[][]transpose(boolean[][] inputMatrix)
transpose
int nr = inputMatrix.length;
int nc = inputMatrix[0].length;
boolean[][] o = new boolean[nc][nr];
for (int i = 0; i < nr; i++) {
    for (int j = 0; j < nc; j++) {
        o[j][i] = inputMatrix[i][j];
return o;
boolean[][]transpose(boolean[][] matrix)
return the transpose of a boolean matrix
if (matrix == null) {
    return null;
int m = matrix.length;
int n = matrix[0].length;
boolean[][] t = new boolean[n][m];
for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
...
boolean[][]transpose(boolean[][] toBeTransposed)
transpose
boolean[][] toReturn = new boolean[toBeTransposed[0].length][toBeTransposed.length];
for (int i = 0; i < toBeTransposed.length; i++) {
    for (int j = 0; j < toBeTransposed[0].length; j++) {
        toReturn[j][i] = toBeTransposed[i][j];
return toReturn;
byte[][]transpose(byte[][] d)
transpose
byte[][] ret = new byte[d[0].length][d.length];
for (int i = 0; i < d[0].length; i++) {
    for (int j = 0; j < d.length; j++) {
        ret[i][j] = d[j][i];
return ret;
double[]transpose(double array[], int W, int H, int D)
transpose
int L = array.length;
double[] out = new double[L];
for (int k = 0; k < D; k++) {
    for (int j = 0; j < H; j++) {
        for (int i = 0; i < W; i++) {
            out[j + H * i + k * W * H] = array[i + W * j + k * W * H];
return out;