0
0
NumPydata~10 mins

np.linspace() for evenly spaced 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 an array of 5 numbers evenly spaced between 0 and 10.

NumPy
import numpy as np
arr = np.linspace(0, 10, [1])
print(arr)
Drag options to blanks, or click blank then click option'
A5
B10
C3
D7
Attempts:
3 left
💡 Hint
Common Mistakes
Using 10 instead of 5 creates more points than needed.
Forgetting the third argument defaults to 50 points.
2fill in blank
medium

Complete the code to create 4 numbers evenly spaced between 1 and 2.

NumPy
import numpy as np
arr = np.linspace(1, [1], 4)
print(arr)
Drag options to blanks, or click blank then click option'
A2
B4
C3
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 or 4 as the end value changes the range incorrectly.
Confusing the number of points with the end value.
3fill in blank
hard

Fix the error in the code to generate 6 numbers from 0 to 5.

NumPy
import numpy as np
arr = np.linspace(0, 5, [1])
print(arr)
Drag options to blanks, or click blank then click option'
A4
B5
C6
D7
Attempts:
3 left
💡 Hint
Common Mistakes
Using 5 generates only five numbers, missing one point.
Using 7 generates too many points.
4fill in blank
hard

Fill both blanks to create an array of 7 numbers from 10 to 20.

NumPy
import numpy as np
arr = np.linspace([1], [2], 7)
print(arr)
Drag options to blanks, or click blank then click option'
A10
B15
C20
D25
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping start and end values.
Using 15 or 25 changes the range incorrectly.
5fill in blank
hard

Fill all three blanks to create a dictionary with keys as numbers from 1 to 5 and values as their squares using np.linspace().

NumPy
import numpy as np
numbers = np.linspace([1], [2], [3])
squares = {int(num): int(num)**2 for num in numbers}
print(squares)
Drag options to blanks, or click blank then click option'
A1
B5
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using 10 as the end value changes the range incorrectly.
Using fewer or more than 5 points changes the keys.