Bird
0
0

Why does np.mean() return a float even when all array elements are integers?

hard📝 Conceptual Q10 of 15
NumPy - Aggregation Functions
Why does np.mean() return a float even when all array elements are integers?
ABecause mean is an average which can be fractional, so output is float
BBecause NumPy converts all integers to floats internally
CBecause <code>np.mean()</code> always returns a string
DBecause the array must contain floats to use <code>np.mean()</code>
Step-by-Step Solution
Solution:
  1. Step 1: Understand what mean represents

    Mean is the sum divided by count, which can produce fractional values.
  2. Step 2: Explain data type of result

    To represent fractional results, np.mean() returns a float even if input is integer.
  3. Final Answer:

    Because mean is an average which can be fractional, so output is float -> Option A
  4. Quick Check:

    Mean output is float to handle fractions [OK]
Quick Trick: Mean can be fractional, so output is float [OK]
Common Mistakes:
  • Thinking output matches input type
  • Assuming conversion to string
  • Believing floats are required input

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes