public static double[][] truncateRows(double[][] matrix,int nCols){
  final int nRows=matrix.length;
  final double[][] result=new double[nRows][nCols];
  for (int row=0; row < nRows; row++) {
    System.arraycopy(matrix[row],0,result[row],0,nCols);
  }
  return result;
}

public static double [ ] [ ] truncateRows ( double [ ] [ ] matrix , int nCols ) { final int nRows = matrix . length ; final double [ ] [ ] result = new double [ nRows ] [ nCols ] ; for ( int row = 0 ; row < nRows ; row ++ ) { System . arraycopy ( matrix [ row ] , 0 , result [ row ] , 0 , nCols ) ; } return result ; }
copy only first ncols of matrix
