Bird
0
0

What is the dtype of the result when you run this code?

medium📝 Predict Output Q13 of 15
NumPy - Array Operations
What is the dtype of the result when you run this code?
import numpy as np
arr1 = np.array([1, 2, 3], dtype=np.int32)
arr2 = np.array([1.5, 2.5, 3.5], dtype=np.float64)
result = arr1 + arr2
dtype_result = result.dtype
Aint32
Bobject
Cfloat32
Dfloat64
Step-by-Step Solution
Solution:
  1. Step 1: Identify input array dtypes

    arr1 is int32, arr2 is float64.
  2. Step 2: Understand type promotion rules

    When adding int32 and float64, NumPy promotes to float64 to preserve precision.
  3. Final Answer:

    float64 -> Option D
  4. Quick Check:

    int32 + float64 = float64 [OK]
Quick Trick: Higher precision float wins in mixed int-float ops [OK]
Common Mistakes:
  • Assuming result is int32
  • Confusing float32 with float64
  • Expecting object dtype for numeric arrays

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes