Python Practice › NumPy Programs › Program 52

Add one row to another

EasyNumPy Programs · 52 of 100

Write a NumPy program to add row 2 to row 1.

Advertisement
Input
[[6, 5], [10, 9], [7, 8]]
Output
[[16 14]
 [10  9]
 [ 7  8]]

Approach

  1. a[0] += a[1].

Solution

Python
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]]
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More numpy programs

← All 100 NumPy Programs