0
0
NumPydata~20 mins

np.arange() for range arrays in NumPy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
np.arange() Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of np.arange() with float step
What is the output of this code snippet using np.arange()?
NumPy
import numpy as np
result = np.arange(1.0, 2.0, 0.3)
print(result)
A[1. 1.3 1.6 1.9 2.2]
B[1. 1.3 1.6]
C[1. 1.3 1.6 1.9]
D[1. 1.3 1.6 1.9 2.0]
Attempts:
2 left
💡 Hint
Remember that np.arange stops before reaching the stop value.
data_output
intermediate
1:30remaining
Length of array from np.arange() with negative step
How many elements are in the array created by this code?
NumPy
import numpy as np
arr = np.arange(5, 0, -1)
print(len(arr))
A5
B4
C6
D0
Attempts:
2 left
💡 Hint
Count numbers from 5 down to but not including 0, stepping by -1.
Predict Output
advanced
2:00remaining
Output of np.arange() with integer step and float start
What is the output of this code?
NumPy
import numpy as np
result = np.arange(0.5, 5, 1)
print(result)
A[0.5 1.5 2.5 3.5 4.5]
B[0.5 1.5 2.5 3.5]
C[1.5 2.5 3.5 4.5]
D[0.5 1.5 2.5 3.5 4.5 5.5]
Attempts:
2 left
💡 Hint
np.arange includes start and increments by step until reaching or passing stop.
visualization
advanced
2:30remaining
Plotting np.arange() output
Which plot correctly shows the points generated by np.arange(0, 3, 0.5)?
NumPy
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 3, 0.5)
plt.scatter(x, [1]*len(x))
plt.xticks(x)
plt.yticks([])
plt.show()
APoints at 0, 0.25, 0.5, 0.75, 1 on x-axis
BPoints at 0, 1, 2, 3 on x-axis
CPoints at 0.5, 1, 1.5, 2, 2.5, 3 on x-axis
DPoints at 0, 0.5, 1, 1.5, 2, 2.5 on x-axis
Attempts:
2 left
💡 Hint
Check the start, stop, and step values carefully.
🧠 Conceptual
expert
2:00remaining
Why might np.arange() produce unexpected results with floats?
Why can np.arange() sometimes produce arrays with unexpected last elements when using float steps?
ABecause np.arange() always rounds the stop value to the nearest integer
BBecause floating point arithmetic can cause rounding errors affecting the stop condition
CBecause np.arange() converts all floats to integers internally
DBecause np.arange() ignores the step value when it is a float
Attempts:
2 left
💡 Hint
Think about how computers store decimal numbers.