0
0
NumPydata~20 mins

np.zeros() for zero-filled arrays in NumPy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Zero Hero
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of np.zeros with shape and dtype
What is the output of this code snippet?
import numpy as np
arr = np.zeros((2, 3), dtype=int)
print(arr)
NumPy
import numpy as np
arr = np.zeros((2, 3), dtype=int)
print(arr)
A
[[0. 0. 0.]
 [0. 0. 0.]]
B
[[0 0 0]
 [0 0 0]]
C
[[0 0 0 0]
 [0 0 0 0]]
D[0 0 0 0 0 0]
Attempts:
2 left
💡 Hint
Check the shape and data type specified in np.zeros.
data_output
intermediate
1:30remaining
Number of elements in np.zeros array
How many elements are in the array created by this code?
import numpy as np
arr = np.zeros((4, 5))
print(arr.size)
NumPy
import numpy as np
arr = np.zeros((4, 5))
print(arr.size)
A20
B9
C10
D5
Attempts:
2 left
💡 Hint
Multiply the dimensions of the shape to find total elements.
🔧 Debug
advanced
2:00remaining
Identify the error in np.zeros usage
What error does this code produce?
import numpy as np
arr = np.zeros(3, 4)
print(arr)
NumPy
import numpy as np
arr = np.zeros(3, 4)
print(arr)
ATypeError: data type not understood
BTypeError: 'int' object is not iterable
CTypeError: zeros() missing 1 required positional argument: 'dtype'
DTypeError: zeros() takes 1 positional argument but 2 were given
Attempts:
2 left
💡 Hint
Check the function signature of np.zeros.
🚀 Application
advanced
2:30remaining
Create a 3D zero-filled array and check shape
Which option creates a 3D zero-filled array with shape (2, 3, 4) and prints its shape correctly?
A
arr = np.zeros([2, 3, 4])
print(arr.shape)
B
arr = np.zeros(2, 3, 4)
print(arr.shape)
C
arr = np.zeros((2, 3, 4))
print(arr.shape)
D
arr = np.zeros({2, 3, 4})
print(arr.shape)
Attempts:
2 left
💡 Hint
np.zeros expects shape as a tuple or list as first argument.
🧠 Conceptual
expert
3:00remaining
Memory size of np.zeros array
Given this code:
import numpy as np
arr = np.zeros((1000, 1000), dtype=np.float64)
print(arr.nbytes)

What is the output value printed?
NumPy
import numpy as np
arr = np.zeros((1000, 1000), dtype=np.float64)
print(arr.nbytes)
A8000000
B4000000
C1000000
D16000000
Attempts:
2 left
💡 Hint
Each float64 uses 8 bytes. Multiply by total elements.