Issue
Is there a Scipy or Numpy function that does the job of dsearchn
MATLAB command in python?
dsearchn
returns the index of nearest value to the input value in the given vector.
Solution
A method of approximately equivalent efficiency is probably scipy's KDTree
or better yet cKDTree
:
from scipy.spatial import KDTree
kdt = KDTree(P.T)
kdt.query(PQ.T)
Here P
and PQ
are the points and query points from the dsearch
docs. MATLAB uses the first dimension as the dimensionality of the points, while scipy uses the last, hence the transpose.
Unlike the MATLAB approach, which is done in a single step, using a KDTree
us done in two steps: first you construct the tree object, then you run a query
on it.
Answered By - Mad Physicist
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.