Skip to content

DOC update shape of returned array in BinaryTree.query #18969

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

Merged
merged 1 commit into from
Dec 19, 2020
Merged

DOC update shape of returned array in BinaryTree.query #18969

merged 1 commit into from
Dec 19, 2020

Conversation

Kot271828
Copy link
Contributor

Method query returns the values which have the shape X.shape[:-1] + (k,).
But docstring seems to be tuple + integer.

What does this implement/fix? Explain your changes.

Clarify the return value's shape.

Method ```query``` returns the values which have the shape X.shape[:-1] + (k,).
But docstring seems to be tuple + integer.
@glemaitre
Copy link
Member

I was using KernelDensity and the underlying tree_ attribute to check the shape when querying. It seems that the shape is a ndarray of shape (X.shape[:-1], k), isn't it?

@glemaitre glemaitre changed the title [update] improve docstring for BinaryTree DOC update shape of returned array in BinaryTree.query Dec 15, 2020
@Kot271828
Copy link
Contributor Author

Thanks for the comment and the title change.

Sorry, I don't know that (X.shape[:-1], k) is equal to X.shape[:-1] + (k,) as notation.
To be precise, (X.shape[:-1], k) is a tuple of tuple and int.
And X.shape[:-1] + (k,) is a tuple of int.
(I'm sorry if that's not what you intended.)

Example is as follows.

>>> import numpy as np
>>> from sklearn.neighbors import KDTree
>>> rng = np.random.RandomState(0)
>>> X = rng.random_sample((10, 3))
>>> tree = KDTree(X, leaf_size=2)
>>> k = 5
>>> dist, ind = tree.query(X, k=k)
>>> X.shape
(10, 3)
>>> X.shape[:-1] + k
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can only concatenate tuple (not "int") to tuple
>>> X.shape[:-1] + (k,)
(10, 5)
>>> (X.shape[:-1], k)
((10,), 5)
>>> dist.shape
(10, 5)
>>> ind.shape
(10, 5)

@glemaitre
Copy link
Member

My bad, my brain misread X.shape[-1] and X.shape[:-1]. Thus, it makes sense.

@glemaitre glemaitre merged commit 54375d2 into scikit-learn:master Dec 19, 2020
@glemaitre
Copy link
Member

Thanks @Kot271828

@Kot271828 Kot271828 deleted the improve_docstring_for_binary_tree branch December 20, 2020 00:09
glemaitre pushed a commit to glemaitre/scikit-learn that referenced this pull request Dec 22, 2020
@glemaitre glemaitre mentioned this pull request Dec 22, 2020
14 tasks
@glemaitre glemaitre mentioned this pull request Apr 22, 2021
12 tasks
glemaitre pushed a commit to glemaitre/scikit-learn that referenced this pull request Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants