Bird
0
0

What is the output of the following code?

medium📝 Predict Output Q13 of 15
NumPy - Creating Arrays
What is the output of the following code?
import numpy as np
arr = np.ones((2, 2), dtype=float)
print(arr)
A[[1 1] [1 1]]
B[[1. 1.] [1. 1.]]
C[[1 1 1] [1 1 1]]
D[[0. 0.] [0. 0.]]
Step-by-Step Solution
Solution:
  1. Step 1: Understand the shape and dtype

    The shape is (2, 2), so the array has 2 rows and 2 columns. The dtype is float, so elements are floats.
  2. Step 2: Predict the printed output

    Each element is 1.0, printed as 1. with a decimal point. So the output is a 2x2 array of 1.0 values.
  3. Final Answer:

    [[1. 1.] [1. 1.]] -> Option B
  4. Quick Check:

    Shape (2,2) and float type means 1.0 values [OK]
Quick Trick: Float dtype shows decimal points in output [OK]
Common Mistakes:
  • Confusing integer and float output formats
  • Misreading shape as (2,3)
  • Expecting zeros instead of ones

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes