public static double[] getDiagonal(final double[][] m1) {
    final int dim = Math.min(getColumnDimensionality(m1), m1.length);
    final double[] diagonal = new double[dim];
    for(int i = 0; i < dim; i++) {
      diagonal[i] = m1[i][i];
    }
    return diagonal;
  }
public static double [ ] getDiagonal ( final double [ ] [ ] m1 ) { final int dim = Math . min ( getColumnDimensionality ( m1 ) , m1 . length ) ; final double [ ] diagonal = new double [ dim ] ; for ( int i = 0 ; i < dim ; i ++ ) { diagonal [ i ] = m1 [ i ] [ i ] ; } return diagonal ; }
getDiagonal returns array of diagonal-elements.

@param m1 Input matrix
@return values on the diagonal of the Matrix