NumPy array 1.Numpy Array Object
The multidimensional array in NumPy is called Ndarray, and he has two components.
1. The data itself
2. Metadata describing the data
Numeric type of 2.Numpy
BOOL: Boolean type
Inti: The length of the platform depends on the integer (usually int32 or Int64)
int8: Byte type
Int16: Integral type
Int32: Integral type
Int64: Integral type
Uint8: Unsigned integral type
UInt16: Unsigned integral type
UInt32: Unsigned integral type
UInt64: Unsigned integral type
Float16: Semi-precision floating-point type
Float32: Single-precision floating-point type
Float64 or float: double-precision floating-point
complex64: plural type
complex128 or complex: plural type
Remember: do not convert the plural type to integer, which will cause an error. , it is also not allowed to convert complex numbers into floating-point numbers.
3. Slicing and indexing of one-dimensional arrays
The slice operation of a one-dimensional array numpy array is the same as a slice of a python list.
In:a=np.arange (9) in:a[3:7]out:array ([3,4,5 ,6]) in:a[:7:2]out:array ([0,2, 4,6])
4. Working with array shapes
You can use the following functions to manipulate the shape of an array
1. Disassembly: You can use the Ravel () function to transform a multidimensional array into a one-dimensional array, a.ravel ()
2. Straighten: The name of the flatten () function is very appropriate, its function is the same as Ravel (), however, flatten () returns a real array, need to allocate new memory space, and the Ravel () function returns only the view of the array
3. Use tuples to specify array shapes: In addition to the reshape () function, you can use tuples to easily define the shape of an array.
4. Transpose: Row variable column, column row. A.transpose ()
5. Resizing: function resize () acts like reshape () but changes the array that is acting
Stacking arrays
1. Horizontal Overlay
The same effect can be achieved with the CONCATENATE () function
2. Vertical Overlay
The concatenate () function also gets the same effect when the parameter axis is set to 0 o'clock
3. Depth Overlay
This method overlays a stack of arrays along the direction of the third axis (portrait).
4. Column Stacking
The Column_stack () function stacks a one-dimensional array in column form
5. Row-Stacked
Splitting numpy arrays
Related functions Hsplit (), Vsplit (), Dsplit (), and split (). We can either divide the array into an array of the same shape, or we can begin to cut the array from the specified position.
1. Split horizontally
The split () function equivalent to calling the parameter Axis=1:
2. Split vertically
When the parameter Axis=0,split () function also decomposes the array along the vertical axis
3. Deep split
The premise is that there must be depth.
Array properties for NumPy
Ndim: The number of dimensions that are stored
Size: The number of elements to save
ItemSize: Can return the number of bytes occupied by each element in the array
Nbytes: The number of bytes required for the entire array
T: Same as transpose () function, transpose
Real: This property returns the real part
Imag: This property returns the imaginary part
Flat property: You can return a Numpy.flatiter object, which is the only way to get the Flatiter object, but we cannot access the Flatiter constructor. You can use flat iterators to iterate through an array, just as you would with a "fat" array
Conversion of arrays
1.Numpy arrays into a python list using the ToList () function
The 2.astype () function converts an array element to a specified type
Broadcast of NumPy arrays
NumPy will try to handle the action when the object is not the same shape
For example, suppose an array is multiplied by a scalar, and the scalar needs to be extended according to the shape of the array before the multiplication can be performed. This extended process is called broadcasting.
"Python data analysis" note 1--numpy