Bird
0
0

You have a 3x3 NumPy array arr and want to add scalar 10 to only the second row using broadcasting. Which code achieves this correctly?

hard📝 Application Q8 of 15
NumPy - Broadcasting
You have a 3x3 NumPy array arr and want to add scalar 10 to only the second row using broadcasting. Which code achieves this correctly?
Aarr[1] = arr[1] + 10
Barr + 10
Carr[:, 1] + 10
Darr[1, :] + 10
Step-by-Step Solution
Solution:
  1. Step 1: Understand row selection and broadcasting

    To add 10 only to second row, select row 1 and add scalar 10.
  2. Step 2: Check options for correct syntax

    arr[1] = arr[1] + 10 correctly updates second row in place. arr + 10 adds to whole array, A adds to second column, D computes but does not assign.
  3. Final Answer:

    arr[1] = arr[1] + 10 -> Option A
  4. Quick Check:

    Assign after adding scalar to selected row [OK]
Quick Trick: Select row, add scalar, assign back to update [OK]
Common Mistakes:
  • Adding scalar to whole array
  • Adding to column instead of row
  • Not assigning result back

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes