Another way is to use the clip function:
using the eumiro example:
bad_array = np.array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]]) maxs = np.array([7,6,5,4]) good_array = bad_array.clip(max=maxs-1)
OR
bad_array.clip(max=maxs-1, out=good_array)
you can also specify a lower limit by adding the argument min =
source share