[SciPy-User] Vector comparison

denis denis-bz-gg@t-online...
Thu Feb 25 04:57:10 CST 2010


On Feb 25, 12:44 am, e...@depagne.org wrote:
> Hi all,
>
> I have two sets of vectors, one made of 3-dim vectors and the other one of 4-
> dims vectors.
>
> I want to find for each of my 3D vectors (let's call them the input vector),
> which one, among my 4D vectors (let's call them my models), has the 3 first
> coordinates that are the closest of my input vector, so that i can assign to
> my input vector the 4th dimension taken from the models.

Éric.
   does this one-liner make sense:
    def nearvec( x, vecs ):
        """ the vec nearest x, -> the pair (norm(x - v), v) """
        return min( (np.linalg.norm( x - v[:3] ), v)  for v in vecs )
# py min, not np.min

Of course change "norm" to xT.A.x if you have an A that weights the
different components,
e.g. 1 / sigmaj^2.

Numpy experts can vectorize just about anything
(a wiki for vectorization examples would be nice, may well exist
already ?)

cheers
  -- denis


More information about the SciPy-User mailing list