Skip to content

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

Open
ToheartZhang wants to merge 1 commit intorougier:masterfrom
ToheartZhang:master
Open

FEAT change #61 to find 3 nearest values in order#140
ToheartZhang wants to merge 1 commit intorougier:masterfrom
ToheartZhang:master

Conversation

@ToheartZhang
Copy link
Copy Markdown

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

Comment thread source/exercises100.ktx

< 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
Copy Markdown
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".

Comment thread source/exercises100.ktx
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
Copy Markdown
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.

2 participants