Bird
0
0

Why does np.array() sometimes create arrays with dtype=object when given nested Python lists?

hard📝 Conceptual Q10 of 15
NumPy - Creating Arrays
Why does np.array() sometimes create arrays with dtype=object when given nested Python lists?
ABecause numpy always uses object dtype for nested lists
BBecause inner lists have different lengths or types
CBecause Python lists are immutable
DBecause np.array() cannot handle nested lists
Step-by-Step Solution
Solution:
  1. Step 1: Understand numpy array dtype assignment

    Numpy tries to create arrays with uniform shape and type.
  2. Step 2: Effect of uneven inner lists

    If inner lists differ in length or type, numpy cannot create uniform array, so uses dtype=object to store elements as generic Python objects.
  3. Final Answer:

    Because inner lists have different lengths or types -> Option B
  4. Quick Check:

    Uneven nested lists cause dtype=object arrays [OK]
Quick Trick: Uneven inner lists cause dtype=object arrays [OK]
Common Mistakes:
  • Thinking numpy always uses object dtype
  • Confusing immutability with dtype
  • Assuming np.array() cannot handle nested lists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes