Basic knowledge
The ndarray object in NumPy is a multi-dimensional array of the same data type.
The number of rank (ndarray.ndim) axes, or the number of dimensions, is a scalar.- The array dimension (ndarray.shape)
is a tuple that describes the size of the array in each dimension. Relative to a matrix, shape represents n rows and m columns. The length of the tuple is equivalent to the number of axes/dimensions, that is, the rank value.
Calculation principle when setting axis
-
Create array
-
The output result is 3 channels, 4 rows, 2 columns
-
Correspondence
numpy When creating an array, each additional [] means adding a dimension, one [] can be regarded as a complete block, there are several blocks under each layer [], and the value corresponding to shape is how many.
-
Calculation principle when axis=0
-
Calculation principle when axis=1
-
Calculation principle when axis=2
High-dimensional transpose() visualization
- The transposition of a one-dimensional array is still its own, without distinguishing between row vector and column vector: numpy.T.
- The transposition of a two-dimensional array is the same as the matrix transposition of linear algebra: numpy.T.
- The transpose of high-dimensional arrays requires the numpy method: transpose(). The transposition of high-dimensional arrays is more difficult to understand, and you cannot imagine the transposition of linear algebra. The transposition here is the change of the position of the underlying number, and the transformation rules follow the rules of the transpose() method.
Index conversion perspective understanding
Coordinate axis change angle understanding
-
Create a multidimensional array
-
The expression
3 of the high-order matrix in NumPy is that the shape of the array b is (2,2,4), which means that there are two 2x4 matrices:
-
Position in high-dimensional coordinate system
-
Position after coordinate axis transformation
-
Visual changes before and after the coordinate axis changes
-
Move the transformed position intact to the original coordinate system to obtain a new array of coordinate axis transformation thickness.
-
In the original coordinate system, the newly placed array shape is still (2,2,4), that is, it contains two 2x4 matrices. The two matrices are sorted in order on the 0 axis, and they are the green cube and the blue cube in the figure.
-
Changes in all 3 axes
Visualization of 1D/2D data processing
-
Create array
-
Array arithmetic
-
index
-
polymerization
-
Create matrix
-
Matrix arithmetic
-
Dot product
-
Matrix index
-
Matrix aggregation
-
Transpose and reshape
-
More dimensions
[References]
The meaning of dimension, axis, and rank in
NumPy Visualization of NumPy data processing Visualization of
transpose() function in Numpy Visual understanding
of Numpy.transpose()
numpy matrix dimension axis in Python Parameter understanding