Challenge - 5 Problems
Zero Hero
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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)
Attempts:
2 left
💡 Hint
Check the shape and data type specified in np.zeros.
✗ Incorrect
np.zeros creates an array of zeros with the given shape and data type. Here, shape is (2,3) and dtype is int, so the output is a 2x3 array of integer zeros.
❓ data_output
intermediate1: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)
Attempts:
2 left
💡 Hint
Multiply the dimensions of the shape to find total elements.
✗ Incorrect
The shape (4,5) means 4 rows and 5 columns, so total elements = 4 * 5 = 20.
🔧 Debug
advanced2: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)
Attempts:
2 left
💡 Hint
Check the function signature of np.zeros.
✗ Incorrect
np.zeros expects the first argument to be the shape as a single tuple or int. Passing two separate ints causes a TypeError about argument count.
🚀 Application
advanced2: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?
Attempts:
2 left
💡 Hint
np.zeros expects shape as a tuple or list as first argument.
✗ Incorrect
Option C correctly passes a tuple as shape. Option C uses a list which also works but is less common. Option C passes multiple arguments causing error. Option C uses a set which is unordered and invalid.
🧠 Conceptual
expert3:00remaining
Memory size of np.zeros array
Given this code:
What is the output value printed?
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)
Attempts:
2 left
💡 Hint
Each float64 uses 8 bytes. Multiply by total elements.
✗ Incorrect
The array has 1,000,000 elements (1000*1000). Each float64 uses 8 bytes. Total bytes = 1,000,000 * 8 = 8,000,000 bytes.