Using numpy built into the maximum and minimum element is faster than where . The notes in the numpy docs for maximum confirm this:
Equivalent to np.where (x1> x2, x1, x2), but faster and does the right broadcast.
The line you want for the first test will look something like this:
fmin = np.minimum(f1, f2); fmax = np.maximum(f1, f2)
My own results show that it is pretty fast. Note that minimum and maximum will work on any n-dimensional array if the two arguments have the same shape.
Using amax 3.506 Using sort 1.830 Using where 0.635 Using numpy maximum, minimum 0.178
source share