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

the answer of question 45 is not exactly correct. #55

Open
i5cnc opened this issue Dec 27, 2017 · 5 comments
Open

the answer of question 45 is not exactly correct. #55

i5cnc opened this issue Dec 27, 2017 · 5 comments

Comments

@i5cnc
Copy link

i5cnc commented Dec 27, 2017

For example:
z = np.array([1, 2, 3, 4, 5, 5], dtype=int)
z[z.argmax()] = 0
print(z)
will output:
[1 2 3 4 0 5]

But for this question, the correct answer should be:
[1 2 3 4 0 0]

@rougier
Copy link
Owner

rougier commented Dec 28, 2017

You're right. Do you have a proposal for the correct answer ?

@dfeather
Copy link

try this?
z = np.random.randint(1, 5, 10)
print(z)
m = z.max()
z[z == m] = 0
print(z)

@rougier
Copy link
Owner

rougier commented Jan 2, 2018

Or even simpler (z.max() will be evaluated only once):

z = np.random.randint(1, 5, 10)
z[z ==z.max()] = 0
print(z)

@lealb
Copy link

lealb commented Jun 16, 2019

as the answer, can use
Z[Z==Z.argmax()]=0

zhukpm added a commit to zhukpm/numpy-100 that referenced this issue Jan 18, 2020
zhukpm added a commit to zhukpm/numpy-100 that referenced this issue Jan 18, 2020
@ghost
Copy link

ghost commented Sep 15, 2020

import numpy as np
x = np.random.random(15)
print("Original array:")
print(x)
x[x.argmax()] = 0
print("Maximum value replaced by 0:")
print(x) # use this

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

No branches or pull requests

4 participants