Python Practice › NumPy Programs › Program 37

Sum of each column

EasyNumPy Programs · 37 of 100

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

Advertisement
Input
[[5, 3], [7, 4]]
Output
[12  7]

Approach

  1. sum(axis=0).

Solution

Python
import numpy as npprint(np.array([[5, 3], [7, 4]]).sum(axis=0))
Output
[12  7]
Advertisement

Learn the concept

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

More numpy programs

← All 100 NumPy Programs