1. Python quantitative transaction - numpy of the three swordsmen
編輯:Python
Catalog
One 、 Environmental installation
1 - anaconda install
2 - jupyter Introduce
3 - cell brief introduction
4 - cell Shortcut key
Two 、numpy Three ways to create
1 - np.array establish numpy
2 - plt.imread establish numpy
3 - Use np Of routines Function creation
3、 ... and 、numpy Common properties
Four 、numpy operation
1 - numpy Index operation
2 - numpy Slicing operation
3 - reshape deformation
4 - Cascade operation
5 - Aggregation operation
6 - Mathematical functions
7 - Statistical function
5、 ... and 、numpy matrix
6、 ... and 、jupyter note
One 、 Environmental installation
1 - anaconda install
anaconda brief introduction :anaconda It's an integrated environment —— It integrates all the environments needed in data analysis and machine learning
anaconda Official website :www.anaconda.com
anaconda download : Tsinghua University image -anaconda, Drag it to the bottom , choice “Anaconda3-5.3.1-Windows-x86_64.exe”
anaconda install :anaconda The installation directory cannot have Chinese and special symbols ; All the way Next, Check “Add Anaconda…” and “Register Anaconda…”
anaconda Test the installation for success : open cmd window , entry jupyter notebook Instructions , If the command cannot be found is not displayed and no error is reported, the installation is successful
2 - jupyter Introduce
What is? jupyter:jupyter Namely anaconda Provides a browser based visual development tool
jupyter start-up : Start the terminal , Then navigate to the specified directory ( In which directory to start , When the time comes jupyter The project of is in which directory ); Enter... In the terminal :jupyter notebook, Press enter
newly build python3:python3 yes anaconda Source files in
anaconda Duplicate file name
Returning to the previous level, you can see that there is one more aaaa.ipynb The file of ,ipynb It's based on anaconda A document of
3 - cell brief introduction
What is? cell
cell There are two patterns :code Pattern 、markdown Pattern
cell Mode switching
4 - cell Shortcut key
add to cell:a= At present cell Add a... Above cell,b= At present cell Add a... Below cell
What is? numpy:NumPy(Numerical Python) yes Python Language is the base of scientific computing . It's about numerical calculation , Most of them Python The foundation of Scientific Computing Library , Mostly used in large 、 Numerical operations performed on multidimensional arrays
1 - np.array establish numpy
np.array() establish numpy
param1:object —— data source
param2:dttype —— The type of array element , The default value is the type passed in from the initial data source
What is the difference between an array and a list
The data element type stored in the array must be a uniform type
Not specified dttype when , Determine the array element type according to the element type priority —— character string > floating-point > Integers
2 - plt.imread establish numpy
Load an external picture to numpy Array , Then try changing the values of the array elements , See the impact on the original picture
If there's a mistake here , Need to install pillow,cmd perform :pip install pillow
3 - Use np Of routines Function creation
np Of routines function
zero(): fill 0 Array of
ones(): fill 1 Array of
linespace()
arange()
random series
np.ones
param1:shape —— Dimension of array —— Shape of the new array, e.g., (2, 3) or 2
np.linspace: establish A one-dimensional An array of arithmetical sequences of
np.arange: establish A one-dimensional A sequence of equal differences
np.random.randint: Create random arrays
3、 ... and 、numpy Common properties
attribute
shape: Return array shape
ndim: Return array dimension
size: Returns the number of array elements
dtype: Array element type
type(arr): Data type of array
Four 、numpy operation
1 - numpy Index operation
numpy Index operation is the same as list operation
2 - numpy Slicing operation
section : Row and column slice
Cut out the first two rows of data
Cut out the first two columns of data
Cut out the data of the first two columns of the first two rows
section : Array data flipping ( The horse )
Original picture
practice : Flip a picture up, down, left and right
practice : Crop the picture in the specified area
3 - reshape deformation
4 - Cascade operation
What is cascade operation : Will be multiple numpy Array ( The dimensions must be the same ) Transverse or longitudinal splicing
axis Axial understanding :0 —— Column ;1 —— That's ok
5 - Aggregation operation
Common aggregation operations : No, axis Parameters —— Please all ;axis=0 —— By column ;axis=1 —— Press the line
sum: Sum up
max: Maximum
min: minimum value
mean: Average
6 - Mathematical functions
numpy Standard trigonometric functions :sin()、cos()、tan()
numpy.around(a, decimals): Function returns the rounding value of a specified number
Parameters a: Array
Parameters decimals: The number of decimal places rounded ; The default value is 0; If a negative , Integers are rounded to the left of the decimal point
7 - Statistical function
Commonly used statistical functions
numpy.amin() and numpy.amax(), Used to calculate the smallest number of elements in an array along a specified axis 、 Maximum
numpy.ptp(): Calculates the difference between the maximum value and the minimum value of an element in an array ( Maximum - minimum value )
numpy.median() Function to evaluate an array a The median of the middle elements ( The median )
Standard deviation std(): Standard deviation is a measure of the dispersion of the average of a set of data .
The formula :std = sqrt(mean((x - x.mean())**2))
If the array is [1,2,3,4], Then the average value is 2.5. therefore , The square of the difference is [2.25,0.25,0.25,2.25], And the square of the average is 4, namely sqrt(5/4) , The result is 1.1180339887498949.
variance var(): Variance in Statistics ( Sample variance ) Is the average of the square of the difference between each sample value and the average of all sample values , namely mean((x - x.mean())** 2). let me put it another way , The standard deviation is the square root of variance
5、 ... and 、numpy matrix
Linear algebra is based on the derivation of matrices :https://www.cnblogs.com/alantu2018/p/8528299.html
numpy matrix
NumPy Contains a matrix library numpy.matlib, The function in this module returns a matrix , instead of ndarray object . One The matrix of is a matrix composed of rows (row) Column (column) A rectangular array of elements
numpy.matlib.identity() Function returns the unit matrix of a given size . Unit matrix is a square matrix , The diagonal from the top left to the bottom right ( Called the main diagonal ) The elements on are 1, All but 0
matrix multiplication : Every number in the first row of the first matrix (2 and 1), Multiply each by the number in the first column of the second matrix (1 and 1), Then add the product ( 2 x 1 + 1 x 1), Get the value of the upper left corner of the result matrix 3. in other words , The result matrix is the second m Lines and n The value at which the columns intersect , It's equal to the first matrix m The row is the same as the second matrix n Column , The sum of the products of each value of the corresponding position