Bird
0
0

Which of the following is the correct way to create a contiguous numpy array from a list?

easy📝 Syntax Q3 of 15
NumPy - Fundamentals
Which of the following is the correct way to create a contiguous numpy array from a list?
Anp.array([1, 2, 3], contiguous=True)
Bnp.array([1, 2, 3], order='C')
Cnp.array([1, 2, 3], layout='contiguous')
Dnp.array([1, 2, 3], memory='contiguous')
Step-by-Step Solution
Solution:
  1. Step 1: Recall numpy array creation syntax

    np.array() accepts an order parameter to specify memory layout.
  2. Step 2: Identify valid parameter for contiguous layout

    order='C' creates a C-contiguous array; other options are invalid parameters.
  3. Final Answer:

    np.array([1, 2, 3], order='C') -> Option B
  4. Quick Check:

    Use order='C' to ensure contiguous array [OK]
Quick Trick: Use order='C' to create contiguous arrays [OK]
Common Mistakes:
  • Using invalid parameters
  • Assuming contiguous=True exists
  • Confusing layout with order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes