- Iterating means going through elements one by one.
- While dealing with multi-dimensional arrays in Numpy, we can perform the basic "for" loop of Python.
import numpy as np
arr = np.array([1,2,3])
for x in arr:
print(x)
In a 1D array, iteration goes through each element one by one.
ab = np.array([[1,2,3], [4,5,6]])
for x in ab:
print(x)
In a 2D array, iteration goes through all of the rows.
abc = np.array([[[1,2,3],[4,5,6]], [[7,8,9],[10,11,12]]])
for x in abc:
print(x)
In a 3D array, iteration will go through all 2D arrays.
NOTE: If we iterate on an n-D array, it'll go through (n-1)th dimension one by one.