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. I am currently maximizing the cosine of two vectors, but I was wondering if scipy had some more clever routines, that could for instance take into account measurement errors for my vectors. Thanks a lot. Éric. -- Un clavier azerty en vaut deux ----------------------------------------------------------
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
Hi Denis,
É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 I'll have a look at it and see how different the results are from my own method.
Of course change "norm" to xT.A.x if you have an A that weights the different components, e.g. 1 / sigmaj^2. Thanks for this, I was looking desperately to find how to include the weights.
Numpy experts can vectorize just about anything (a wiki for vectorization examples would be nice, may well exist already ?)
Cheers, Éric.
cheers -- denis _______________________________________________ SciPy-User mailing list SciPy-User@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user
-- Un clavier azerty en vaut deux ---------------------------------------------------------- Éric Depagne edepagne@lcogt.net
participants (3)
-
denis
-
eric@depagne.org
-
Éric Depagne