box diagram
box_1, box_2, box_3= Z_Acol["Y"], Z_Bcol["Y"], Z_Ccol["Y"]
labels = ['type A','type B','type C']
plt.title('Box plot of size of three fishing rod types')
plt.ylabel('size')
plt.boxplot([box_1, box_2, box_3], labels = labels)
-------------------------------------------------------------------------------------------------------------
Find an element in an array and return its index, the type is tuple
plt.plot(range(0,300),MSEset)
r = np.where(MSEset == np.max(MSEset))
r2 = np.where(MSEset == np.min(MSEset))
plt.text(r[0][0], np.max(MSEset), round(np.max(MSEset)))
plt.text(r2[0][0], np.min(MSEset), round(np.min(MSEset)))
-------------------------------------------------------------------------------------------------------------
Generate a random symmetric and positive definite matrix
sklearn.datasets.make_spd_matrix(n_dim, *, random_state=None)[source]
来自 <sklearn.datasets.make_spd_matrix — scikit-learn 1.0.1 documentation>
-------------------------------------------------------------------------------------------------------------
x/y calculates the corresponding element division
-------------------------------------------------------------------------------------------------------------
Plt.contour(xp,yp,zp,5) Draw contour lines, xp, yp, zp must be 2d
-------------------------------------------------------------------------------------------------------------
Plt.axes('scaled') //Make the unit length of the long section of the graphics equal
-------------------------------------------------------------------------------------------------------------
Np.multiply() is for the matrix to multiply the corresponding elements or use *
Np.dot Matrix multiplication is inner product for vectors
-------------------------------------------------------------------------------------------------------------
plt.subplots_adjust(wspace=0.3) wspace represents the spacing between graphs
-------------------------------------------------------------------------------------------------------------
np.linalg.norm() function
Returns the norm result of a matrix or array
-------------------------------------------------------------------------------------------------------------
np.c_[U,np.ones([N,1])]
add a column
Np.r_[]
add a line
-------------------------------------------------------------------------------------------------------------
from sklearn.model_selection import train_test_split
#Split the data into training set and test set
X_train, X_test, t_train, t_test = train_test_split(X, t, test_size=0.3)
X is the input, t is the output, automatically divide the data set into training set and test set
--------------------------------------------------------------------------------------------
np.square(X)
Square each element in the matrix and return this matrix
np.linalg.own()
@ is the computation of the matrix multiplication
——————————————————————————————————
use of dot()
dot() returns the dot product of two arrays
1. If you are dealing with a one-dimensional array, you get the inner product of the two arrays
In : d = np.arange(0,9)
Out: array([0, 1, 2, 3, 4, 5, 6, 7, 8])
In : e = d[::-1]
Out: array([8, 7, 6, 5, 4, 3, 2, 1, 0])
In : np.dot(d,e)
Out: 84
2. If it is an operation between two-dimensional arrays (matrixes), the result is a matrix product (mastrix product).
In : a = np.arange(1,5).reshape(2,2)
Out:
array([[1, 2],
[3, 4]])
In : b = np.arange(5,9).reshape(2,2)
Out: array([[5, 6],
[7, 8]])
In : np.dot(a,b)
Out:
array([[19, 22],
[43, 50]])
—————————————————————————————————————————
numpy.random.randn(d0,d1,…,dn)
- The randn function returns a sample or set of samples, with a standard normal distribution.
- dn table each dimension
- The return value is an array of the specified dimension
numpy.random.rand(d0,d1,…,dn)
- The rand function generates data between [0,1) according to the given dimension , including 0 and excluding 1
- dn table each dimension
- The return value is an array of the specified dimension
From < numpy.random.randn() usage_u012149181's blog-CSDN blog_np.random.randn >
-----------------------------------------------------------------------------------------------------------------------------
Cholesky decomposition
- L = numpy.linalg.cholesky(a) returns the Cholesky decomposition a = L*LT of a positive definite matrix a , where L is lower triangular.
From < numpy. Basic operations of linear algebra_mycsdnnum's blog-CSDN blog >
The role of Np.random.permutation
For example, the data before using this function is [1,2,3,4,5,6]
After using [3,5,6,1,2,4]
Meshgrid Preface
The meshgrid function is to draw a grid on a plane with points on two coordinate axes (of course, when there are two parameters passed in here). Of course, we can specify multiple parameters, such as three parameters, then we can use the points on the three one-dimensional coordinate axes to draw a grid on the three-dimensional plane.
The role of Plt.meshgrid is to combine the individual horizontal and vertical coordinates, and each x and y are matched once
For three dimensions, the parameters are three one-dimensional arrays, and the shapes of the one-dimensional arrays are N, M, and P respectively. Then if indexing = 'xy', the returned three matrices xv, yv, and zv have the shapes (M,N,P); if indexing = 'ij', the three matrices xv, yv, and zv are all of shape (N,M,P)
From < Python-Numpy module Meshgrid function - know almost >