if (m.getColumnDimension() == 1) {
double[][] d = new double[m.getRowDimension()][m.getRowDimension()];
for (int i = 0; i < m.getRowDimension(); i++) {
d[i][i] = m.getEntry(i, 0);
}
return new Array2DRowRealMatrix(d, false);
} else {
double[][] d = new double[m.getRowDimension()][1];
for (int i = 0; i < m.getColumnDimension(); i++) {
d[i][0] = m.getEntry(i, i);
}
return new Array2DRowRealMatrix(d, false);
}
}