Python Practice › NumPy Programs › Program 70

Print every element

EasyNumPy Programs · 70 of 100

Write a NumPy program to print every element of a 2-D array.

Advertisement
Input
[[4, 8, 0], [2, 0, 6]]
Output
4 8 0 2 0 6 

Approach

  1. np.nditer or ravel().

Solution

Python
import numpy as npa = np.array([[4, 8, 0], [2, 0, 6]])for x in np.nditer(a):    print(x, end=" ")print()
Output
4 8 0 2 0 6 

Learn the concept

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

More numpy programs

← All 100 NumPy Programs

Leave a Comment