WORKING WITH LOOPS
Listing 2.2 displays the content of loop1.py that illustrates how to iterate through the elements of a NumPy array and a Python list.
LISTING 2.2: loop1.py
import numpy as np list = [1,2,3] arr1 = np.array([1,2,3]) for e in list: print(e) for e in arr1: print(e)
Listing 2.2 initializes the variable list, which is a Python list, and also the variable arr1, which is a NumPy array. The next portion of Listing 2.2 contains two loops, each of which iterates through the elements in list and arr1. As you can see, the syntax is identical in both loops. The output from launching Listing 2.2 is here:
1 2 3 1 2 3