Challenge - 5 Problems
Array Creation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of NumPy arange with float step
What is the output of this code snippet?
import numpy as np result = np.arange(0, 1, 0.3) print(result)
Data Analysis Python
import numpy as np result = np.arange(0, 1, 0.3) print(result)
Attempts:
2 left
💡 Hint
Remember that arange excludes the stop value and uses step increments.
✗ Incorrect
np.arange starts at 0 and adds 0.3 repeatedly until it reaches or passes 1. It stops before 1, so 1 is not included.
❓ data_output
intermediate1:30remaining
Number of elements in linspace with endpoint=False
How many elements does this array have?
import numpy as np arr = np.linspace(2, 10, 5, endpoint=False) print(len(arr))
Data Analysis Python
import numpy as np arr = np.linspace(2, 10, 5, endpoint=False) print(len(arr))
Attempts:
2 left
💡 Hint
The number of points is controlled by the third argument, regardless of endpoint.
✗ Incorrect
linspace creates exactly the number of points specified by the third argument, here 5, even if endpoint is False.
❓ visualization
advanced2:30remaining
Visual difference between arange and linspace
Which plot correctly shows the difference between np.arange(0, 1, 0.2) and np.linspace(0, 1, 6)?
Data Analysis Python
import numpy as np import matplotlib.pyplot as plt x1 = np.arange(0, 1, 0.2) x2 = np.linspace(0, 1, 6) plt.plot(x1, np.zeros_like(x1), 'o', label='arange') plt.plot(x2, np.ones_like(x2), 'x', label='linspace') plt.legend() plt.show()
Attempts:
2 left
💡 Hint
arange excludes the stop value, linspace includes it by default.
✗ Incorrect
np.arange(0,1,0.2) produces 5 points excluding 1, np.linspace(0,1,6) produces 6 points including 1.
🧠 Conceptual
advanced1:30remaining
Behavior of np.linspace with num=1
What is the output of this code?
import numpy as np arr = np.linspace(5, 10, 1) print(arr)
Data Analysis Python
import numpy as np arr = np.linspace(5, 10, 1) print(arr)
Attempts:
2 left
💡 Hint
When num=1, linspace returns the start value only.
✗ Incorrect
np.linspace with num=1 returns an array with the start value only, ignoring the stop value.
🔧 Debug
expert1:30remaining
Identify the error in this array creation code
What error does this code raise?
import numpy as np arr = np.arange(0, 10, 0) print(arr)
Data Analysis Python
import numpy as np arr = np.arange(0, 10, 0) print(arr)
Attempts:
2 left
💡 Hint
Step size cannot be zero in range or arange functions.
✗ Incorrect
np.arange raises ValueError if step is zero because it cannot progress through the range.