Python Practice › NumPy Programs › Program 85

Sum of all columns

EasyNumPy Programs · 85 of 100

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

Advertisement
Input
[[6, 5, 7], [10, 9, 1], [7, 8, 2]]
Output
[23 22 10]

Approach

  1. sum(axis=0).

Solution

Python
import numpy as npprint(np.array([[6, 5, 7], [10, 9, 1], [7, 8, 2]]).sum(axis=0))
Output
[23 22 10]
Advertisement

Learn the concept

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

More numpy programs

← All 100 NumPy Programs