Bird
0
0

What will be printed by the following code?

medium📝 Predict Output Q4 of 15
NumPy - Creating Arrays
What will be printed by the following code?
import numpy as np
arr = np.full((3, 1), 8)
print(arr)
A[8 8 8]
B[[8] [8] [8]]
C[[8 8 8]]
D[[1] [1] [1]]
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the shape argument

    The shape (3, 1) means 3 rows and 1 column.
  2. Step 2: Understand the fill value

    The array will be filled with the value 8 in every element.
  3. Step 3: Expected output

    Printing the array will display a 3x1 array with each element as 8, shown as:
    [[8] [8] [8]]
  4. Final Answer:

    [[8] [8] [8]] -> Option B
  5. Quick Check:

    Shape (3,1) means 3 rows, 1 column [OK]
Quick Trick: Shape (3,1) creates 3 rows and 1 column [OK]
Common Mistakes:
  • Misinterpreting shape (3,1) as a 1D array
  • Confusing row and column dimensions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes