diff --git a/src/main/java/com/mattrixwv/matrix/IntegerMatrix.java b/src/main/java/com/mattrixwv/matrix/IntegerMatrix.java index 02e6872..a9cde9a 100644 --- a/src/main/java/com/mattrixwv/matrix/IntegerMatrix.java +++ b/src/main/java/com/mattrixwv/matrix/IntegerMatrix.java @@ -478,6 +478,20 @@ public class IntegerMatrix{ } //Complex operations + public IntegerMatrix transpose(){ + //Create a new grid + int[][] newGrid = new int[getNumCols()][getNumRows()]; + + //Traverse every element in the existing grid and add each column to the new grid as a row + for(int col = 0;col < getNumCols();++col){ + for(int row = 0;row < getNumRows();++row){ + newGrid[col][row] = grid[row][col]; + } + } + + //Return the new matrix + return new IntegerMatrix(newGrid); + } //Object funtions @Override