Bird
0
0

What does this code print?

medium📝 Predict Output Q5 of 15
NumPy - Fundamentals
What does this code print?
import numpy as np
arr = np.arange(12).reshape(3,4)
transposed = arr.T
print(transposed.flags.f_contiguous)
AFalse
BNone
CRaises an error
DTrue
Step-by-Step Solution
Solution:
  1. Step 1: Understand transpose effect on memory layout

    Transpose changes array to Fortran order (column-major) contiguous.
  2. Step 2: Check f_contiguous flag for transposed array

    Transposed array is contiguous in Fortran order, so flag is True.
  3. Final Answer:

    True -> Option D
  4. Quick Check:

    Transpose makes array Fortran contiguous = True [OK]
Quick Trick: Transpose often creates Fortran contiguous arrays [OK]
Common Mistakes:
  • Expecting C-contiguous after transpose
  • Confusing flags.f_contiguous with c_contiguous
  • Assuming transpose breaks contiguity

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes