5

I am trying to delete every 8th column in a 1024x1024 matrix using this method but it takes a lot of time and it will be more difficult when I have to process millions of matrices. Could you please show me how can I delete every nth row or column starting from a certain row or column and using numpy, scipy or any other Python package?

Many thanks

1 Answer 1

6

You can use np.delete giving the indices corresponding to every 8th row index. Let a be a 2D array or a matrix:

np.delete(a, list(range(0, a.shape[0], 8)), axis=0)

note the use of axis=0 indicating to operate along the rows. To operate along the columns:

np.delete(a, list(range(0, a.shape[1], 8)), axis=1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.