In NumPy, what is the result of the operation np.array([1, 2, 3]) + 5?

2026

In NumPy, what is the result of the operation
np.array([1, 2, 3]) + 5?

  1. A.

    An error

  2. B.

    [6, 7, 8]

  3. C.

    [1, 2, 3, 5]

  4. D.

    [5, 10, 15]

Attempted by 123 students.

Show answer & explanation

Correct answer: B

In NumPy, adding a scalar to an array performs element-wise addition. The operation np.array([1, 2, 3]) + 5 adds 5 to each element: 1+5=6, 2+5=7, and 3+5=8. The resulting array is [6, 7, 8].

Explore the full course: Rssb Senior Computer Instructor