Bird
0
0

Find the error in this code that tries to create a NumPy array:

medium📝 Debug Q14 of 15
NumPy - Creating Arrays
Find the error in this code that tries to create a NumPy array:
import numpy as np
arr = np.array(1, 2, 3)
print(arr)
AThe print statement is missing parentheses.
Bnp.array() needs a single list or array argument, not multiple separate arguments.
Cnp.array() cannot create arrays from numbers.
DThe import statement is incorrect.
Step-by-Step Solution
Solution:
  1. Step 1: Check np.array() argument format

    np.array() expects one argument, usually a list or array, not multiple separate values.
  2. Step 2: Identify the error in the code

    The code passes three separate arguments instead of one list, causing a TypeError.
  3. Final Answer:

    np.array() needs a single list or array argument, not multiple separate arguments. -> Option B
  4. Quick Check:

    Single argument list required = C [OK]
Quick Trick: np.array() takes one list or array argument [OK]
Common Mistakes:
  • Passing multiple arguments instead of one list
  • Thinking np.array() can't take numbers
  • Misreading print syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes