0
0
NumPydata~10 mins

np.ones() for one-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 1D array of length 5 filled with ones.

NumPy
import numpy as np
array = np.[1](5)
print(array)
Drag options to blanks, or click blank then click option'
Aones
Bzeros
Cempty
Dfull
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.zeros() which creates an array of zeros instead of ones.
Using np.empty() which creates an uninitialized array.
2fill in blank
medium

Complete the code to create a 2x3 array filled with ones.

NumPy
import numpy as np
array = np.ones([1])
print(array)
Drag options to blanks, or click blank then click option'
A(3, 2)
B(2, 3)
C[2, 3]
D[3, 2]
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping rows and columns in the shape tuple.
Using a list instead of a tuple for the shape.
3fill in blank
hard

Fix the error in the code to create a 3x3 array of ones with integer type.

NumPy
import numpy as np
array = np.ones((3, 3), dtype=[1])
print(array)
Drag options to blanks, or click blank then click option'
Aint
B'float'
C'int'
Dinteger
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'integer' which is not a valid dtype string.
4fill in blank
hard

Fill both blanks to create a 4x4 array of ones with float type and print its shape.

NumPy
import numpy as np
array = np.ones([1], dtype=[2])
print(array.shape)
Drag options to blanks, or click blank then click option'
A(4, 4)
B'float'
C'int'
D(4,)
Attempts:
3 left
💡 Hint
Common Mistakes
Using a one-dimensional shape like (4,) instead of (4, 4).
Using 'int' instead of 'float' for dtype.
5fill in blank
hard

Fill all three blanks to create a 2x5 array of ones with integer type and print the array.

NumPy
import numpy as np
array = np.ones([1], dtype=[2])
print([3])
Drag options to blanks, or click blank then click option'
A(2, 5)
B'int'
Carray
D'float'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'float' instead of 'int' for dtype.
Printing a wrong variable name.