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

voidtranspose(final double[][] src, final double[][] dest, int l1, int l2)
Transposes the source matrix in the destination matrix.
assert src != null;
assert dest != null;
assert hasShape(src, l1, l2);
assert hasShape(dest, l2, l1);
for (int i = 0; i < l1; i++) {
    for (int j = 0; j < l2; j++) {
        dest[j][i] = src[i][j];
float[]transpose(float[] mat, float[] dest)
transpose
if (dest == null || mat == dest) {
    float a0 = mat[1], a2 = mat[2], a5 = mat[5];
    mat[1] = mat[3];
    mat[2] = mat[6];
    mat[3] = a0;
    mat[5] = mat[7];
    mat[6] = a2;
    mat[7] = a5;
...
voidtranspose(float[][] data)
Transposes the given (square) two-dimensional array in place.
float tmp;
for (int ii = 0; ii < data.length; ii++) {
    for (int jj = ii + 1; jj < data.length; jj++) {
        tmp = data[ii][jj];
        data[ii][jj] = data[jj][ii];
        data[jj][ii] = tmp;
voidtranspose(int N, double src[][])
transpose
for (int i = N - 1; i >= 0; i--) {
    for (int j = i - 1; j >= 0; j--) {
        double tmp = src[i][j];
        src[i][j] = src[j][i];
        src[j][i] = tmp;
int[][]transpose(int[][] input)
transpose
int[][] output = new int[input[0].length][input.length];
for (int i = 0; i < input.length; i++) {
    for (int j = 0; j < input[0].length; j++) {
        output[j][i] = input[i][j];
return output;
int[][]transpose(int[][] M)
Takes the transpose of an array (like the matrix operation).
int[][] Mt = new int[M[0].length][M.length];
for (int i = 0; i < M.length; i++) {
    if (M[i].length != M[0].length) {
        throw new IllegalArgumentException("The array is not a matrix.");
    for (int j = 0; j < M[0].length; j++) {
        Mt[j][i] = M[i][j];
return (Mt);
int[][]transpose(int[][] matrix)
transpose
if (matrix.length == 0 || matrix[0].length == 0)
    return matrix;
int[][] result = new int[matrix[0].length][matrix.length];
for (int i = 0; i < matrix.length; i++) {
    for (int j = 0; j < matrix[0].length; j++) {
        int delta = (int) ((Math.random() * 20 - 10) / 9);
        delta *= (int) (Math.random() * 3);
        result[j][i] = matrix[i][j] + delta;
...
voidtranspose(int[][][] as, int A, int[][][] ast)
create transpose of sparse matrix
int M = as[0].length;
Map<Integer, Integer>[] x = new Map[A];
for (int m = 0; m < M; m++) {
    for (int n = 0; n < as[0][m].length; n++) {
        int ii = as[0][m][n];
        if (x[ii] == null) {
            x[ii] = new HashMap<Integer, Integer>();
        x[ii].put(m, as[1][m][n]);
map2sparse(x, ast);
long[]transpose(long[] a, double offset)
transpose
long[] result = Arrays.copyOf(a, a.length);
for (int i = 0; i < a.length; i++) {
    result[i] += offset;
return result;
Object[][]transpose(Object[][] matrix)
Transpoe a matriz (Transforma linhas em colunas e vice versa)
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;