mirror of
https://bitbucket.org/Mattrixwv/matrix.git
synced 2025-12-07 07:23:58 -05:00
Added transpose
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user