Java Matrix Transpose matrixTransform(Object[][] datas)

Here you can find the source of matrixTransform(Object[][] datas)

Description

matrix Transform

License

Open Source License

Declaration

public static Object[][] matrixTransform(Object[][] datas) 

Method Source Code

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

import java.util.*;

public class Main {

    public static Object[][] matrixTransform(Object[][] datas) {
        if (datas.length == 0 || datas[0].length == 0) {
            return datas;
        }//from   ww w  . j  a va 2s . c  o m
        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];
            for (int j = 0; j < column; j++) {
                list[j] = datas[j][i];
            }
            newData[i] = list;
        }
        return newData;
    }

    public static <T> List<List<T>> matrixTransform(List<List<T>> datas) {
        if (datas.size() == 0 || datas.get(0).size() == 0) {
            return datas;
        }
        int column = datas.size();
        int row = datas.get(0).size();
        List<List<T>> newData = new ArrayList<>(row);
        for (int i = 0; i < row; i++) {
            List<T> list = new ArrayList<>(column);
            for (int j = 0; j < column; j++) {
                list.add(datas.get(j).get(i));
            }
            newData.add(list);
        }
        return newData;
    }
}

Related

  1. matrixTrans_x_diagonalMatrix(double[][] mat, double[] diag)
  2. matrixTrans_x_diagonalMatrix_x_Matrix(double[][] mat, double[] diag)
  3. matrixTrans_x_matrix(double[][] mat)
  4. matrixTranspose(Object[][] matrix)
  5. transpose(boolean[][] inputMatrix)
  6. transpose(boolean[][] matrix)
  7. transpose(boolean[][] toBeTransposed)