Question 39 solution isn't quite right
Dimitrije-V opened this issue · 4 comments
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.
Let me know if I should create a PR.
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]
Thanks for your analysis. I think the current answer is correct given the question.