[SciPy-User] Get array of separation vectors from an array a vectors

davide_fiocco@yah... davide_fiocco@yah...
Wed Jan 13 18:47:44 CST 2010

Hi folks,
I'm new to Python and I'm trying to implement a basic molecular
dynamics code.

The problem I have is the following:
Suppose you have an array of N vectors in R^3 like:
A = [ [x1,y1,z1], [x2,y2,z2], ..., [xN,yN,zN] ]

what I need is to get N!/(2! (N-2)!) separation vectors between the
vectors in A, i.e.
D = [ [x1-x2,y1-y2,z1-z2], [x1-x3,y1-y3,z1-z3], ..., [x2-x3,y2-y3,z2-
z3], ...,  [x_i-x_j,y_i-y_j,z_i-z_j],...]

and I need the code to be FAST! Else I think I'll switch to a Fortran/
F2Py implementation.

I'd say this task is not too different to what
scipy.spatial.distance.pdist() does, with the difference that i don't
need (the euclidean, say) distance but the differences between all the
pairs of vectors in A.

All suggestions will be very welcome, and I apologize if this is too
trivial! Thank you.


More information about the SciPy-User mailing list