0
0
NumPydata~10 mins

np.full() for custom-filled 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 3x3 array filled with the number 7 using np.full().

NumPy
import numpy as np
array = np.full((3, 3), [1])
print(array)
Drag options to blanks, or click blank then click option'
A0
B3
C7
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using the shape as the fill value.
Confusing the order of arguments.
2fill in blank
medium

Complete the code to create a 2x4 array filled with the string 'hi' using np.full().

NumPy
import numpy as np
array = np.full((2, 4), [1], dtype=str)
print(array)
Drag options to blanks, or click blank then click option'
A'bye'
B'hi'
C'hello'
D'test'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the string.
Not specifying dtype for string arrays.
3fill in blank
hard

Fix the error in the code to create a 4x2 array filled with 0.5 using np.full().

NumPy
import numpy as np
array = np.full([1], 0.5)
print(array)
Drag options to blanks, or click blank then click option'
A(4, 2)
B[4, 2]
C4, 2
D{4, 2}
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list instead of a tuple for shape.
Using curly braces which create a set.
4fill in blank
hard

Fill both blanks to create a 3x3 array filled with the integer 9 and print its data type.

NumPy
import numpy as np
array = np.full([1], [2], dtype=int)
print(array.dtype)
Drag options to blanks, or click blank then click option'
A(3, 3)
B9
C3
Dfloat
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single number instead of a tuple for shape.
Using a string instead of an integer for fill value.
5fill in blank
hard

Fill all three blanks to create a 2x5 array filled with 3.14, specify float type, and print the array shape.

NumPy
import numpy as np
array = np.full([1], [2], dtype=[3])
print(array.shape)
Drag options to blanks, or click blank then click option'
A(2, 5)
B3.14
Cfloat
Dint
Attempts:
3 left
💡 Hint
Common Mistakes
Using integer dtype for decimal fill values.
Using incorrect shape format.