Q:

Fastest way to compare Numpy ndarrays

I have stored 4 ndarrays in a dictionary dictPrices and would like to generate another boolean ndarray for each of the 2 cases:
(1) element-wise, if number in any of the 4 ndarrays exceed x
(2) element-wise, if number in all of the 4 ndarrays exceed x
dictPrices[1] >= x works but when i tried (dictPrices[1] >= x | dictPrices[2] >= x), it fails. (dictPrices[1] >= x or dictPrices[2] >= x) failed too.
As the ndarrays can be huge (from monte carlo), I was hoping for vectorization rather than to loop through each ndarray element-wise.
Thank you!

A:

I think you want this:
np.logical_or.reduce([prices >= x for prices in dictPrices.values()])

This is explained in some detail here: Numpy `logical_or` for more than two arguments
And of course for the second case you can use logical_and instead of logical_or.

