In a 2-D array, it will iterate through all the rows.
Iterate through the elements of the following 2-D array:
import numpy as np arr = np.array([[1, 2, 3], [4, 5, 6]]) for x in arr: print(x) |
To obtain the actual values, or scalars, we need to iterate through the arrays in each dimension.
Iterate through each scalar element of the 2-D array:
import numpy as np arr = np.array([[1, 2, 3], [4, 5, 6]]) for x in arr: for y in x: print(y) |