Iterating over NumPy arrays can be done in various ways, depending on the specific requirements of your task.
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
for elem in arr:
print(elem)
import numpy as np
arr = np.array([[1, 2], [3, 4]])
for elem in np.nditer(arr):
print(elem)
import numpy as np
arr1 = np.array([1, 2, 3])
arr2 = np.array([4, 5, 6])
result = arr1 + arr2
print(result)
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
# Calculate the square of each element
squared_arr = np.square(arr)
print(squared_arr)