Python Practice › NumPy Programs › Program 36

Sum of each row

EasyNumPy Programs · 36 of 100

Write a NumPy program to calculate the sum of each row.

Advertisement
Input
[[5, 3], [7, 4]]
Output
[ 8 11]

Approach

  1. sum(axis=1).

Solution

Python
import numpy as npprint(np.array([[5, 3], [7, 4]]).sum(axis=1))
Output
[ 8 11]

Learn the concept

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

More numpy programs

← All 100 NumPy Programs

Leave a Comment