WHAT ARE NUMPY ARRAYS?
An array is a set of consecutive memory locations used to store data. Each item in the array is called an element. The number of elements in an array is called the dimension of the array. A typical array declaration is shown here:
arr1 = np.array([1,2,3,4,5])
The preceding code snippet declares arr1 as an array of five elements, which you can access via arr1[0] through arr1[4]. Notice that the first element has an index value of 0, the second element has an index value of 1, and so forth. Thus, if you declare an array of 100 elements, then the 100th element has an index value of 99.
NOTE The first position in a NumPy array has the index “0.”
NumPy treats arrays as vectors. Math operations are performed element-by-element. Remember the following difference: “doubling” an array multiplies each element by 2, whereas “doubling” a list appends a list to itself.
Listing 2.1 displays the content of nparray1.py that illustrates...