Challenge - 5 Problems
One-Filled Arrays Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of np.ones() with shape (3, 2)
What is the output of this code snippet?
NumPy
import numpy as np arr = np.ones((3, 2)) print(arr)
Attempts:
2 left
💡 Hint
np.ones() creates an array filled with 1.0 by default with the given shape.
✗ Incorrect
np.ones((3, 2)) creates a 2D array with 3 rows and 2 columns filled with float 1.0 values.
❓ data_output
intermediate1:30remaining
Shape and dtype of np.ones array
What are the shape and data type of the array created by np.ones((4,))?
NumPy
import numpy as np arr = np.ones((4,)) print(arr.shape, arr.dtype)
Attempts:
2 left
💡 Hint
Default dtype for np.ones is float64 unless specified.
✗ Incorrect
np.ones((4,)) creates a 1D array with 4 elements of type float64 by default.
🔧 Debug
advanced2:00remaining
Error in np.ones() usage
What error does this code produce?
NumPy
import numpy as np arr = np.ones(3, 2) print(arr)
Attempts:
2 left
💡 Hint
np.ones(shape, dtype) interprets the second argument as dtype; check if it's valid.
✗ Incorrect
np.ones(3, 2) passes shape=3 and dtype=2, but 2 is not a valid dtype, raising TypeError: data type not understood.
🚀 Application
advanced1:30remaining
Creating a 3D array of ones with dtype int
Which code creates a 3x3x3 array filled with integer ones?
Attempts:
2 left
💡 Hint
dtype is the correct keyword for data type in numpy arrays.
✗ Incorrect
Option A correctly passes shape as a tuple and dtype as int. Others have syntax errors or wrong keywords.
🧠 Conceptual
expert2:30remaining
Memory usage difference between np.ones and np.zeros
Which statement about memory usage is true when comparing np.ones((1000,1000)) and np.zeros((1000,1000)) with default dtype?
Attempts:
2 left
💡 Hint
Consider how numpy stores array data in memory regardless of values.
✗ Incorrect
Both arrays have the same shape and dtype, so they use the same memory size. Values do not affect memory size in numpy arrays.