Bird
0
0

What is wrong with this code snippet?

medium📝 Debug Q14 of 15
NumPy - Creating Arrays
What is wrong with this code snippet?
import numpy as np
lst = [1, 2, 3]
arr = np.array(lst, 5)
print(arr)
AThe list contains integers which are not allowed.
Bnp.array() does not take a second positional argument like 5.
CThe print statement is missing parentheses.
DThe list must be nested to convert to an array.
Step-by-Step Solution
Solution:
  1. Step 1: Check np.array() function signature

    np.array() takes the data as the first argument; a second positional argument like 5 is invalid.
  2. Step 2: Identify the error caused by extra argument

    Passing 5 as a second positional argument causes a TypeError.
  3. Final Answer:

    np.array() does not take a second positional argument like 5. -> Option B
  4. Quick Check:

    Extra positional arguments cause error [OK]
Quick Trick: np.array() takes one main argument: the list [OK]
Common Mistakes:
  • Thinking list must be nested
  • Forgetting print() needs parentheses (Python 3)
  • Believing integers are not allowed in arrays

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes