Mathematical preliminaries
In order to understand how arrays work in NumPy, it is useful to understand the mathematical parallel between accessing tensor (matrix and vector) elements by indexes and evaluating mathematical functions by providing arguments. We also cover in this section the generalization of the dot product as a reduction operator.
Arrays as functions
Arrays may be considered from several different points of view. We believe that the most fruitful one in order to understand arrays is that of functions of several variables.
For instance, selecting a component of a given vector in ℝ n may just be considered a function from the set of ℕn to ℝ, where we define the set:
Here the set ℕn has n elements. The Python function range
generates ℕn.
Selecting an element of a given matrix, on the other hand, is a function of two parameters, taking its value in ℝ. Picking a particular element of an m × n matrix may thus be considered a function from ℕm × ℕn to ℝ.
Operations are elementwise
NumPy...