I. Overview of NumPy
NumPy (numerical python) provides Python support for multidimensional array objects: Ndarray, with vector computing power, fast and space-saving. NumPy supports advanced large number of dimension and matrix operations, and also provides a large number of mathematical libraries for array operations.
Ii. creating an array of Ndarray
ndarray:n-dimensional array objects (matrices), all elements must be of the same type.
Ndarray Property: The Ndim property, which represents the number of dimensions; the Shape property, which represents the size of each dimension; The Dtype property that represents the data type.
To create an Ndarray array function:
Iii. specifying the type of the Ndarray array element
NumPy Data type:
Vectorization Calculation of Ndarray
Vector operations: An operation between an array key of the same size applied to an element
Vector and scalar operations: "Broadcast"-scalar "broadcast" to individual elements
V. Basic indexes and slices of the Ndarray array
Index of one-dimensional array: Similar to Python's list index function
Index of multidimensional arrays:
- ARR[R1:R2, C1:C2]
- arr[1,1] equivalent arr[1][1]
- [:] represents data for a dimension
Vi. Boolean indexes and fancy indexes for ndarray arrays
Boolean index: Uses a Boolean array as the index. Arr[condition],condition is a Boolean array that consists of one condition/multiple conditions.
Fancy index: Use an integer array as the index.
The transpose of the Ndarray array and the axis swap
The transpose/pivot of an array returns only one view of the source data and does not modify the source data.
Viii. General functions of Ndarray
A general function (UFUNC) is a function that performs an element-level operation on data in Ndarray.
One dollar Ufunc:
Dual Ufunc:
Nine, the WHERE function of NumPy uses
Np.where (condition, x, y), the first parameter is a Boolean array, the second argument and the third parameter can be scalar or an array.
X. Statistical methods commonly used in Ndarray
The data of an entire array/axis can be statistically calculated by these basic statistical methods.
Statistical methods for Boolean arrays:
- Sum: Counts the number of true in a dimension of an array/array
- Any: Statistics array/Array if there is one/more true in a dimension
- All: counts whether the array/array is true in one dimension
Use sort to sort the array/array in-place with a dimension (the arrays themselves are modified).
The de-weight of the Ndarray array and the set operation
12. Linear Algebra in NumPy
Import Numpy.linalg module. Linear algebra (linear algebra)
Common NUMPY.LINALG Module functions:
13. Generation of random numbers in NumPy
Import Numpy.random module.
Common Numpy.random Module functions:
Python's NumPy Library