[SciPy-user] comparing two lists/arrays
Scott Sinclair
scott.sinclair.za@gmail....
Wed Jul 15 07:43:26 CDT 2009
> 2009/7/15 Robert Cimrman <cimrman3@ntc.zcu.cz>:
> nicky van foreest wrote:
>> Given two vectors x and y, the (perhaps) common mathematical
>> definition of x < y is that x_i < y_i for all i. Thus, the
>> mathematical comparison x <y returns just one boolean, not an array of
>> booleans for each x_i < y_i. I implemented this behavior as
>> prod(less(X,Y)) (I use less to be able to deal with lists X and Y
>> also). Is there perhaps a more straighforward/elegant/readible way to
>> achieve the same behavior?
>
> assuming x, y are numpy arrays: (x < y).all()
You could do the following to handle the case where they aren't:
>>> import numpy as np
>>> x = range(10)
>>> y = range(1, 11)
>>> np.all(x < y)
True
Cheers,
Scott
More information about the SciPy-user
mailing list