0
0
NumPydata~10 mins

np.zeros() for zero-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 zero-filled array of length 5.

NumPy
import numpy as np
arr = np.[1](5)
print(arr)
Drag options to blanks, or click blank then click option'
Azeros
Bones
Cempty
Dfull
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.ones() which creates an array filled with ones.
Using np.empty() which creates an uninitialized array with random values.
2fill in blank
medium

Complete the code to create a 2x3 zero-filled array.

NumPy
import numpy as np
arr = np.zeros([1])
print(arr)
Drag options to blanks, or click blank then click option'
A(2, 3)
B[3, 2]
C(3, 2)
D[2, 3]
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the dimensions, creating 3 rows and 2 columns instead.
Using a tuple with wrong order.
3fill in blank
hard

Fix the error in the code to create a zero-filled array of shape (4, 4).

NumPy
import numpy as np
arr = np.zeros([1])
print(arr)
Drag options to blanks, or click blank then click option'
A[4, 4]
B(4, 4)
C{4, 4}
D4, 4
Attempts:
3 left
💡 Hint
Common Mistakes
Passing two separate arguments instead of one tuple.
Using square or curly brackets which are invalid here.
4fill in blank
hard

Fill both blanks to create a zero-filled array of integers with shape (3, 2).

NumPy
import numpy as np
arr = np.zeros([1], dtype=[2])
print(arr)
Drag options to blanks, or click blank then click option'
A(3, 2)
Bint
Cfloat
D[3, 2]
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list instead of a tuple for shape.
Using float instead of int for dtype.
5fill in blank
hard

Fill all three blanks to create a zero-filled 3D array with shape (2, 3, 4) and float data type.

NumPy
import numpy as np
arr = np.zeros([1], dtype=[2], order=[3])
print(arr.shape, arr.dtype)
Drag options to blanks, or click blank then click option'
A(2, 3, 4)
Bfloat
C'C'
D'F'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong shape dimensions or wrong brackets.
Using int instead of float for dtype.
Using 'F' order without understanding memory layout.