New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOC: 1D arrays with KDTree #19188
Comments
The docs do indicate that the
So I'd probably read that as shape I don't know that we'd want to reshape 1-D input by design/automatically--this could also silently allow through a mistake when a user accidentally meant to pass in high dimensional data but only provided a single record/point as a 1-D array of columns. cc @sturlamolden perhaps |
What I'd meant perhaps was that the docs do not mention that 1D data is acceptable if trivially reshaped to 2D: IMO that ExamplesFind the nearest neighbors of a pair of 1D data arrays or lists
|
That data array must be 2-dimensional does not mean that the kd-tree only works for 2-dimensional data. The data array has to be of shape That said, I do not know why anyone would want to use a kd-tree on 1D data. It is the kind of thing a binary search tree (BST) does better. |
for n = 1, true
Well, "better" in this case means a correct result with 4 lines of code - there is no BST function as such in scipy/numpy, and 3rd party like Binary_Search_Trees isn't as succinct and also adds to the project S.O.U.P. tracking required by FDA. |
I have no idea what SOUP tracking is 🤔 |
I'll change to a documentation label then, I think Sturla and I both said pretty similar things. |
No, what I mean is we cannot guess if I think perhaps that the error message is confusing as it could be read as if the the data needs to be |
could be perhaps (from my user perspective)
|
Based on the discussion in scipy#19188, change the error message to make it clearer that we're dealing with a 2D numpy array, but the data in the array can be any dimension (1D, 2D, ...).
#19391) * DOC: Change error message in spatial.KDTree to be more informative. Based on the discussion in #19188, change the error message to make it clearer that we're dealing with a 2D numpy array, but the data in the array can be any dimension (1D, 2D, ...). * Update scipy/spatial/_ckdtree.pyx Co-authored-by: Jake Bowhay <60778417+j-bowhay@users.noreply.github.com> --------- Co-authored-by: Jake Bowhay <60778417+j-bowhay@users.noreply.github.com>
Is your feature request related to a problem? Please describe.
We want to find close values between two 1D arrays of sampled plethysmographic data peaks, 25 sample points in this case.
KDTree does not allow 1D inputs
_ckdtree.pyx line 557
so one has to add an empty dimension at the end:
It took me a while to realize that I could do this as there is no mention in the docs.
Describe the solution you'd like.
Add a test for 1D inputs and promote to 2D, probably right where the ValueError is tested.
Describe alternatives you've considered.
Similar methods using
searchsorted()
orwhere()
are much more difficult to construct the conditions, and using KDTree is simple and elegant.Additional context (e.g. screenshots, GIFs)
The text was updated successfully, but these errors were encountered: