import numpy as np# Create a 1D arrayarr_1d = np.array([1,2,3,4,5])# Iterate through the 1D array using a for loopfor element in arr_1d:print(element,end='')
2D Array Iteration:
import numpy as np# Create a 2D arrayarr_2d = np.array([[1,2,3],[4,5,6],[7,8,9]])# Iterate through the 2D array using nested loopsfor row in arr_2d:for element in row:print(element,end='')print()
3D Array Iteration:
import numpy as np# Create a 3D arrayarr_3d = np.array([[[1,2],[3,4]],[[5,6],[7,8]],[[9,10],[11,12]]])# Iterate through the 3D array using nested loopsfor matrix in arr_3d:for row in matrix:for element in row:print(element,end='')print()print()