Vectorization refers to using an array expression instead of a loop to manipulate each element in the array.
The general functions provided by NumPy (both Ufunc functions) are functions that perform element-level operations on data in Ndarray. For example, the square function computes the square of each element, and the rint function rounds each element:
There are also some functions that accept 2 parameters, called two ufunc, such as the Add function and the maximum function:
numpy.where function
The Numpy.where function is a vectorized version of the ternary expression x if condition else y, for example:
The second and third parameters of the Np.where function are not necessary, and they can all be scalar values, for example:
Mathematical and statistical methods
For example, the Np.sum function can sum elements in an array:
For a two-dimensional array, the SUM function sums all the elements, but the two-dimensional array has two directions for the horizontal and vertical axes, so the sum function can also be summed in the direction of the two-dimensional array:
Data analysis using Python (6) NumPy Basics: Vector Computing