Skip to content
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

FEAT change #61 to find 3 nearest values in order #140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ToheartZhang
Copy link

Change No.61 problem to find 3 nearest values in order.
I ran generators.py and it made some other changes in files.

@@ -778,16 +778,17 @@ Z = np.random.randint(0,3,(3,10))
print((~Z.any(axis=0)).any())

< q61
Find the nearest value from a given value in an array (★★☆)
Find the 3 nearest values in order from a given value in an array (★★☆)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the "in order".

z = 0.5
m = Z.flat[np.abs(Z - z).argmin()]
print(m)
m = Z.flat[np.abs(Z - z).ravel().argpartition(3)[:3]]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefere a one line expression such that people can see directly what is the interesting part. I know that it won't work for all kind of specific cases but the goal here is to highlight argpartition.

print( np.abs(Z - z).argpartition(3)[:3]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants