Bird
0
0

Which of the following is the correct syntax to sum elements of a numpy array arr along axis 1?

easy📝 Conceptual Q3 of 15
NumPy - Aggregation Functions
Which of the following is the correct syntax to sum elements of a numpy array arr along axis 1?
Anp.sum(arr, axis=1)
Bnp.sum(arr, 1, axis=1)
Cnp.sum(arr, axis='1')
Dnp.sum(arr, axis=[1])
Step-by-Step Solution
Solution:
  1. Step 1: Check correct axis parameter type

    The axis parameter must be an integer, not a string or list.
  2. Step 2: Validate syntax

    np.sum(arr, axis=1) uses axis=1 correctly. np.sum(arr, 1, axis=1) provides multiple values for the axis parameter, which is invalid. np.sum(arr, axis='1') uses a string which is invalid. np.sum(arr, axis=[1]) uses a list which is invalid.
  3. Final Answer:

    np.sum(arr, axis=1) -> Option A
  4. Quick Check:

    axis parameter must be int, not string or list [OK]
Quick Trick: Use integer for axis, no quotes or lists [OK]
Common Mistakes:
  • Passing axis as string
  • Passing axis as list
  • Duplicating axis argument

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes