Bird
0
0

Which of the following is the correct syntax to add 5 to every element of a NumPy array arr?

easy📝 Syntax Q3 of 15
NumPy - Array Operations
Which of the following is the correct syntax to add 5 to every element of a NumPy array arr?
Aarr + [5]
Barr + 5
Carr + '5'
Darr.add(5)
Step-by-Step Solution
Solution:
  1. Step 1: Understand scalar addition syntax

    Adding a scalar to an array uses the '+' operator directly.
  2. Step 2: Evaluate options

    Only arr + 5 correctly adds 5 to each element; others cause errors or wrong types.
  3. Final Answer:

    arr + 5 -> Option B
  4. Quick Check:

    Scalar addition syntax = arr + scalar [OK]
Quick Trick: Use '+' operator with scalar to add to array elements [OK]
Common Mistakes:
  • Using string '5' instead of number
  • Trying to add list instead of scalar
  • Using non-existent method add()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes