numpy bring values in a range

Solution 1:

In [49]: x = np.array([-5, 6, 24, 51, 50, 40])

A couple of alternatives:

In [50]: np.clip(x,0,50)
Out[50]: array([ 0,  6, 24, 50, 50, 40])

In [52]: np.minimum(np.maximum(x,0),50)
Out[52]: array([ 0,  6, 24, 50, 50, 40])