Optimising list comparison

Kragen Sitaker kragen at pobox.com
Tue Mar 19 13:59:30 EST 2002


Graham Ashton <graz at mindless.com> writes:
> A friend of mine is using Python in a research project where he needs to
> compare each element of two vectors, such that comparing [a, b, c] and 
> [d, e, f] would involve comparing a with d, b with e and c with f.

Numeric.alltrue(Numeric.logical_or(a == b, Numeric.logical_or(a == -1,
                                                              b == -1)))

It might not be faster than psyco, but it will be faster than looping
in interpreted Python over all the elements of each vector if the
vectors are relatively large.




More information about the Python-list mailing list