Numpy Ndarray object
An important feature of Numpy is its N-dimensional array object ndarray, which is a series of similar data collections, starting with the 0 subscript as the index of the elements in the collection. A multidimensional array similar to C++'s vector.
The following are the characteristics of Ndarray (different from python's list)
The ndarray object is a multidimensional array used to store elements of the same type. (For example: all are float, str, or int, etc., but they must be of the same type.)
Each element in ndarray has the same storage size area in memory
Based on the above characteristics, ndarray is composed of the following contents:
1) A pointer to data (a piece of data in memory or a memory-mapped file).
2) The data type or dtype, which describes the grid of fixed-size values in the array.
3) A tuple representing the shape of the array (shape), representing a tuple of the size of each dimension.
4) A stride, where the integer refers to the number of bytes that need to be "crossed" in order to advance to the next element in the current dimension.
To create an ndarray array, just call the numpy array function:
numpy.array(object, dtype=None, copy=True, order=None, subok=false, ndmin=0)
name | describe |
---|---|
object | array or nested array |
dtype | data structure for array elements, optional |
copy | Whether the object needs to be copied, optional |
order | The style of creating an array, C is the row direction, F is the column direction, and A is any direction |
subbox | Returns an array consistent with the base class by default |
ndmin | Specifies the minimum dimension of the resulting array |
The above is the usage of multi-dimensional arrays in the numpy module of python, and it is necessary to test its usage through Liezi. as follows:
1: Create a one-dimensional array
2: Create a two-dimensional array
3: Test the ndmin parameter
4: Test the parameter dtype parameter
Summary: The narray multidimensional array is a very important part of the numpy module. The operation of the narray array inherits the operation of python. It converts with python's list, str, float, etc.