1

I have an array (100,72) and I need to clip only the values ​​of some columns. For example, I want that only the negative values in the column from 15 to column 72 are set to 0 I have seen that using the np.clip() function it is not possible to do this. Is there a quick way or do I have to decompose and reassemble the array?

1 Answer 1

2

Do this:

arr[:, 15:73] = np.clip(arr[:, 15:73], a_min = 0)

In general, if cols is the list of column indices, you can use arr[:, cols] to perform the operation selectively on the specified columns. Reference: numpy indexing.

Sign up to request clarification or add additional context in comments.

1 Comment

This raises an error because the argument a_max was excluded.

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.