Bird
0
0

Which of the following is the correct way to create a NumPy array from a Python list [1, 2, 3]?

easy📝 Conceptual Q12 of 15
NumPy - Fundamentals
Which of the following is the correct way to create a NumPy array from a Python list [1, 2, 3]?
Anp.array([1, 2, 3])
Bnp.list([1, 2, 3])
Carray([1, 2, 3])
Dnp.array{1, 2, 3}
Step-by-Step Solution
Solution:
  1. Step 1: Recall NumPy array creation syntax

    The function to create a NumPy array is np.array() and it takes a list as input.
  2. Step 2: Check each option for syntax correctness

    np.array([1, 2, 3]) uses correct syntax. np.list([1, 2, 3]) uses a non-existent function np.list(). array([1, 2, 3]) misses the np. prefix. np.array{1, 2, 3} uses curly braces which is invalid.
  3. Final Answer:

    np.array([1, 2, 3]) -> Option A
  4. Quick Check:

    Correct NumPy array syntax = A [OK]
Quick Trick: Use np.array() with square brackets for lists. [OK]
Common Mistakes:
  • Using curly braces instead of square brackets
  • Missing np prefix
  • Using non-existent np.list() function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes