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

Question 39 solution isn't quite right #209

Closed
Dimitrije-V opened this issue May 17, 2024 · 4 comments
Closed

Question 39 solution isn't quite right #209

Dimitrije-V opened this issue May 17, 2024 · 4 comments

Comments

@Dimitrije-V
Copy link

The given solution to the question:

Create a vector of size 10 with values ranging from 0 to 1, both excluded (★★☆)

Is the following code:

Z = np.linspace(0,1,11,endpoint=False)[1:]

However, this is slightly wrong. We are asked to produce a range of values, from 0-1, and exclude 0 and 1 themselves. The provided code, however, generates a list of values ranging from 0, to 0.90909091.
The value of Z, before we slice with [1:], is:

[0.         0.09090909 0.18181818 0.27272727 0.36363636 0.45454545
 0.54545455 0.63636364 0.72727273 0.81818182 0.90909091]

Instead, the code should be:

Z = np.linspace(0,1,11,endpoint=True)[1:-1]

Which produces Z with these values prior to slicing with [1:-1]:
[0. 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1. ]

This is a bit of a nitpick, and I may be missing something, I just thought I saw a small way to contribute to this project and went for it.

@Dimitrije-V
Copy link
Author

Let me know if I should create a PR.

@Dimitrije-V Dimitrije-V changed the title Question 39 Question 39 solution isn't quite right May 17, 2024
@Dimitrije-V
Copy link
Author

I've been silly. The question asks for size 10, and the code I provided produces an array of size 11.
The actual correct code:

Z = np.linspace(0,1,10,endpoint=True)[1:-1]

@Dimitrije-V
Copy link
Author

#210

@rougier
Copy link
Owner

rougier commented May 27, 2024

Thanks for your analysis. I think the current answer is correct given the question.

@rougier rougier closed this as completed May 27, 2024
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

2 participants