You want to create a 3D NumPy array of shape (2, 3, 4) filled with the value 10. Which code correctly does this?
hard📝 Application Q8 of 15
NumPy - Creating Arrays
You want to create a 3D NumPy array of shape (2, 3, 4) filled with the value 10. Which code correctly does this?
Anp.full((2, 3, 4), 10)
Bnp.full([2, 3], 10)
Cnp.full(2, 3, 4, 10)
Dnp.full((2, 3), 4, 10)
Step-by-Step Solution
Solution:
Step 1: Understand the shape for 3D array
The shape (2, 3, 4) means 2 blocks, each with 3 rows and 4 columns.
Step 2: Check correct np.full() syntax
np.full((2, 3, 4), 10) uses a tuple for shape and the fill value 10 correctly. np.full([2, 3], 10) uses incomplete shape (2x3 instead of 2x3x4). Options C and D have wrong argument counts or shapes.
Final Answer:
np.full((2, 3, 4), 10) -> Option A
Quick Check:
Use tuple shape and fill value in np.full() [OK]
Quick Trick:Use tuple for shape even in 3D arrays [OK]
Common Mistakes:
Wrong argument count
Using incomplete shape
Incorrect shape tuple
Master "Creating Arrays" in NumPy
9 interactive learning modes - each teaches the same concept differently