0
0
NumPydata~10 mins

np.arange() for range arrays in NumPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a NumPy array from 0 to 4 using np.arange().

NumPy
import numpy as np
arr = np.arange([1])
print(arr)
Drag options to blanks, or click blank then click option'
A5
B10
C6
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using 4 instead of 5 will create array up to 3 only.
Confusing np.arange() with range() which behaves similarly but returns a list.
2fill in blank
medium

Complete the code to create a NumPy array from 2 to 6 (excluding 6) using np.arange().

NumPy
import numpy as np
arr = np.arange([1], 6)
print(arr)
Drag options to blanks, or click blank then click option'
A0
B2
C1
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or 1 as start will include unwanted numbers.
Forgetting that the stop value is excluded.
3fill in blank
hard

Fix the error in the code to create an array from 1 to 10 with step 2 using np.arange().

NumPy
import numpy as np
arr = np.arange(1, 10, [1])
print(arr)
Drag options to blanks, or click blank then click option'
A3
B1
C2
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using step 0 causes an error.
Using step 1 gives all numbers, not skipping.
4fill in blank
hard

Fill both blanks to create an array from 10 down to 2 (excluding 2) with step -2 using np.arange().

NumPy
import numpy as np
arr = np.arange([1], [2], -2)
print(arr)
Drag options to blanks, or click blank then click option'
A10
B2
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using stop greater than start with negative step results in empty array.
Confusing stop value inclusion.
5fill in blank
hard

Fill all three blanks to create a NumPy array of even numbers from 0 to 8 using np.arange().

NumPy
import numpy as np
arr = np.arange([1], [2], [3])
print(arr)
Drag options to blanks, or click blank then click option'
A0
B10
C2
D8
Attempts:
3 left
💡 Hint
Common Mistakes
Using stop as 8 excludes 8 itself.
Using step 1 gives all numbers, not just even.