Bird
0
0

Which of the following is the correct syntax to create a NumPy array of integers and add it to a float array with automatic type promotion?

easy📝 Syntax Q3 of 15
NumPy - Array Operations
Which of the following is the correct syntax to create a NumPy array of integers and add it to a float array with automatic type promotion?
Anp.array([1, 2, 3]) + np.array([1, 2, 3])
Bnp.array([1, 2, 3], dtype=float) + np.array([1, 2, 3])
Cnp.array([1, 2, 3]) + np.array([1.0, 2.0, 3.0])
Dnp.array([1.0, 2.0, 3.0]) + np.array([1.0, 2.0, 3.0])
Step-by-Step Solution
Solution:
  1. Step 1: Understand the question

    We want to add int array to float array with automatic type promotion.
  2. Step 2: Check each option

    np.array([1, 2, 3]) + np.array([1.0, 2.0, 3.0]) adds int array to float array directly, triggering promotion. Others either use same types or force float on int array.
  3. Final Answer:

    np.array([1, 2, 3]) + np.array([1.0, 2.0, 3.0]) -> Option C
  4. Quick Check:

    Correct syntax for int + float addition [OK]
Quick Trick: Add int array to float array directly for promotion [OK]
Common Mistakes:
  • Forcing dtype unnecessarily
  • Adding arrays of same type only
  • Using incompatible types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes