Numpy delete submatrix

Viewed 77

I have a numpy array of float. I was wondering if there are any methods or functions to cut/delete a part of matrix.

matrix = np.arange(400).reshape(20,20)

I considered extracting by indexing the rows/columns by slicing (Cut(matrix[row_idx,:][:,col_idx])) or using functions np.ix, but that gives me a submatrix, and I need an old matrix without a select part.

The picture below shows what I mean. I want to get a matrix without the column and rows marked in yellow.

enter image description here

Is there any way to do this? Thank you for your any help.

2 Answers

If you want to build a new matrix, you could use concatenate:

newmatrix = np.concatenate(
    (np.concatenate((matrix[:8,:8], matrix[13:, :8])),
     np.concatenate((matrix[:8,13:], matrix[13:, 13:]))),
    axis=1)
Related