[SciPy-User] unravel_index for pdist?
Benjamin Root
ben.root at ou.edu
Wed Jul 27 16:22:54 EDT 2011
Hello,
I typically use pdist() from scipy.spatial.distance to keep some of my
scripts lean wrt memory usage. However, determining which pairs of points a
distance value refers to is a bit tricky. I was wondering if a
"punravel_index()" function might be welcomed?
Here is my algorithm I came up with to perform this action for a single
result. I haven't tested it for anything more general than that. *pntCnt*
is the number of points that pdist() was used for. *index* is an index from
a function like "np.argmax(pdist(p))".
rowcnts = np.cumsum(xrange(pntCnt - 1, 0, -1))
row = np.searchsorted(rowcnts, index)
col = pntCnt - (rowcnts[row] - index)
At the very least, I hope that this is helpful to anybody else using pdist.
Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20110727/314e8e0c/attachment.html>
More information about the SciPy-User
mailing list