Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Numpy delete submatrix

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

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

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading