Bird
0
0

Why does np.prod() return 1 when applied to an empty NumPy array?

hard📝 Conceptual Q10 of 15
NumPy - Aggregation Functions
Why does np.prod() return 1 when applied to an empty NumPy array?
ABecause the product of no numbers is defined as 1 (identity for multiplication)
BBecause it sums elements and empty sum is 1
CBecause it returns the first element by default
DBecause empty arrays cause an error and 1 is default
Step-by-Step Solution
Solution:
  1. Step 1: Understand identity element for multiplication

    The identity for multiplication is 1, meaning multiplying no numbers results in 1.
  2. Step 2: Apply to empty array

    Since there are no elements, np.prod() returns 1 as the neutral product value.
  3. Final Answer:

    Because the product of no numbers is defined as 1 (identity for multiplication) -> Option A
  4. Quick Check:

    Empty product = 1 by definition [OK]
Quick Trick: Empty product returns 1 as multiplication identity [OK]
Common Mistakes:
  • Thinking it sums elements
  • Expecting error on empty array
  • Assuming default is zero

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes