Challenge - 5 Problems
Linspace Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of np.linspace() with default endpoint
What is the output of this code?
import numpy as np arr = np.linspace(0, 1, 5) print(arr)
NumPy
import numpy as np arr = np.linspace(0, 1, 5) print(arr)
Attempts:
2 left
💡 Hint
Remember np.linspace includes the endpoint by default.
✗ Incorrect
np.linspace(0, 1, 5) creates 5 numbers evenly spaced from 0 to 1, including 1.
❓ data_output
intermediate1:30remaining
Number of elements in np.linspace() output
How many elements are in the array created by this code?
import numpy as np arr = np.linspace(10, 20, 11)
NumPy
import numpy as np arr = np.linspace(10, 20, 11) print(len(arr))
Attempts:
2 left
💡 Hint
The third argument is the number of points to generate.
✗ Incorrect
np.linspace(10, 20, 11) generates 11 evenly spaced points between 10 and 20 inclusive.
❓ Predict Output
advanced2:00remaining
Effect of endpoint=False in np.linspace()
What is the output of this code?
import numpy as np arr = np.linspace(0, 1, 5, endpoint=False) print(arr)
NumPy
import numpy as np arr = np.linspace(0, 1, 5, endpoint=False) print(arr)
Attempts:
2 left
💡 Hint
Setting endpoint=False excludes the stop value.
✗ Incorrect
With endpoint=False, np.linspace excludes the stop value and divides the interval into equal parts accordingly.
🧠 Conceptual
advanced1:30remaining
Understanding np.linspace() step size
If you run
np.linspace(2, 8, 4), what is the step size between consecutive elements?Attempts:
2 left
💡 Hint
Step size = (stop - start) / (number_of_points - 1)
✗ Incorrect
The step size is (8 - 2) / (4 - 1) = 6 / 3 = 2, but check carefully.
🔧 Debug
expert2:00remaining
Identify the error in np.linspace() usage
What error does this code raise?
import numpy as np arr = np.linspace(5, 1, -3) print(arr)
NumPy
import numpy as np arr = np.linspace(5, 1, -3) print(arr)
Attempts:
2 left
💡 Hint
Number of samples must be zero or positive integer.
✗ Incorrect
np.linspace requires the number of samples to be non-negative. Negative values cause ValueError.