How to compute the maximum between an array and a number element by element?

arrays, numpy, python

Solution

`np.maximum` computes the element-wise maximum of array elements, and numpy has some broadcasting rules ( see here ); so you can try this:

np.maximum(x, 0)

Problem

I have a numpy array and I would like to have the maximum between each value and 0. ``` array([ 7.1788812 , 7.16842748, 7.1601692 , 7.16941517, -30.89416777, -30.89403639, -30.89971925, -30.89529326, -31.59193447, -31.59202963]) ``` Wanted result: ``` array([ 7.1788812 , 7.16842748, 7.1601692 , 7.16941517,0,0,0,0,0,0]) ``` There are different ways to obtain the result but I would like something of short and very pythonic

Original source