If you can process many values ββat a time, you can try to understand the list:
a = [1,1,5,1,1] b = [7,2,8,5,3] c = [3,3,3,3,3] [min(y,max(x,z)) for x,y,z in zip(a, b, c)] [3, 2, 5, 3, 3]
or even numpy:
import numpy as np a = np.array(a) b = np.array(b) c = np.array(c) np.minimum(b, np.maximum(a, c)) np.minimum(b, np.maximum(a, 3))
source share