Python Practice › NumPy Programs › Program 52
Add one row to another
Write a NumPy program to add row 2 to row 1.
Input
[[6, 5], [10, 9], [7, 8]]
Output
[[16 14] [10 9] [ 7 8]]
Approach
a[0] += a[1].
Solution
import numpy as npa = np.array([[6, 5], [10, 9], [7, 8]])a[0] += a[1]print(a)Output
[[16 14] [10 9] [ 7 8]]
Learn the concept
New to this topic? Read the lesson, then come back.