Python Practice › NumPy Programs › Program 70
Print every element
Write a NumPy program to print every element of a 2-D array.
Input
[[4, 8, 0], [2, 0, 6]]
Output
4 8 0 2 0 6
Approach
np.nditerorravel().
Solution
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.