Optimising list comparison

Fernando Pérez fperez528 at yahoo.com
Fri Mar 15 11:08:09 EST 2002


Graham Ashton wrote:

> 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.
> 

Are your vectors 3-d only? If so, I assume you're worried about performance 
because you have *many* of them. The fastest (super-easy) way to do it is to 
shove them into two 3xN NumPy matrices and do the comparison there. You can 
then compare them and will get a _fast_ comparison done by Numeric, with all 
the necessary information for extracting the differing elements.

Just some thoughts,

f.



More information about the Python-list mailing list