Replace element in numpy array using some condition

Viewed 667

For example, I have some array like:

>>> x = np.arange(-5, 4).reshape(3, 3)
>>> x
array([[-5, -4, -3],
       [-2, -1,  0],
       [ 1,  2,  3]])

How can I replace all elements with b which are greater then a otherwise set them to 0?

I tried

np.place(x, lambda y: b if y > a else 0)

But it didn't work out.

2 Answers
Related