public Matrix slice ( int fromRow , int fromColumn , int untilRow , int untilColumn ) { ensureIndexArgumentsAreInBounds ( fromRow , fromColumn ) ; ensureIndexArgumentsAreInBounds ( untilRow - 1 , untilColumn - 1 ) ; if ( untilRow - fromRow < 0 || untilColumn - fromColumn < 0 ) { fail ( "Wrong slice range: [" + fromRow + ".." + untilRow + "][" + fromColumn + ".." + untilColumn + "]." ) ; } Matrix result = blankOfShape ( untilRow - fromRow , untilColumn - fromColumn ) ; for ( int i = fromRow ; i < untilRow ; i ++ ) { for ( int j = fromColumn ; j < untilColumn ; j ++ ) { result . set ( i - fromRow , j - fromColumn , get ( i , j ) ) ; } } return result ; }
Retrieves the specified sub - matrix of this matrix . The sub - matrix is specified by intervals for row indices and column indices .