public DenseMatrix selectColumns(int[] columnIndices) {
        if (columnIndices == null || columnIndices.length == 0) {
            throw new IllegalArgumentException("Invalid column indices.");
        }
        DenseMatrix returnVal = new DenseMatrix(dim1,columnIndices.length);

        for (int i = 0; i < dim1; i++) {
            for (int j = 0; j < columnIndices.length; j++) {
                int curIdx = columnIndices[j];
                if (curIdx < 0 || curIdx >= dim2) {
                    throw new IllegalArgumentException("Invalid column index, expected [0, " + dim2 +"), found " + curIdx);
                }
                returnVal.values[i][j] = get(i,curIdx);
            }
        }

        return returnVal;
    }
@Test
    public void selectColumnsTest() {
        DenseMatrix a = generateSquareRandom(8, new Random(42));
        DenseMatrix columns = a.selectColumns(new int[] {0,5,7});
        assertEquals(8, columns.getShape()[0]);
        assertEquals(3, columns.getShape()[1]);
        assertEquals(a.getColumn(0), columns.getColumn(0));
        assertEquals(a.getColumn(5), columns.getColumn(1));
        assertEquals(a.getColumn(7), columns.getColumn(2));
    }