Some uses of NP
Np.a
Np.array ([1,2,3],dtype=int) #建立一个One-dimensional array,
Np.array ([[[1,2,3],[2,3,4]]) #建立一个 a two-dimensional array.
Np.arange (2,3,0.1) #起点, end point, step value. Contains the start value, without the end value.
np.m
Np.mean to find the mean value. The parameters for the regular operation are axis, with an example of the M * N Matrix:
Axis does not set a value, m*n the number of values, and returns a real
Axis = 0: Compress rows, mean values for each column, return 1* n matrix
Axis = 1: Compressed column, averaging for each row, returns m * * Matrix
>>> Import NumPy as NP
>>> NUM1 = Np.array ([[1,2,3],[2,3,4],[3,4,5],[4,5,6]])
>>> now2 = Np.mat (NUM1)
>>> Now2
Matrix ([[1, 2, 3],
[2, 3, 4],
[3, 4, 5],
[4, 5, 6]])
>>> Np.mean (NOW2) # Averaging for all elements
3.5
>>> Np.mean (now2,0) # compressing rows, averaging values for each column
Matrix ([[[2.5, 3.5, 4.5]])
>>> Np.mean (now2,1) # Compression column, averaging for each row
Matrix ([[2.],
[3.],
[4.],
[5.]])
Np.i
Innner (A, b) is used to calculate the inner product; outer (A, B) calculates the outer product.
Np.z
Np.zeros ((2,3)) #生成一个2行3列的全0矩阵. Note that the parameter is a tuple: (2,3), so there are two parentheses. The complete form is: Zeros (shape,dtype=). The same structure, with ones () establishes a full 1 matrix. Empty () creates an empty matrix, using random values in memory to populate the matrix.
The identity (n) #建立n the unit array of the *N, which can only be a square.
Eye (n,m=none,k=0) #建立一个对角线是1其余值为0的矩阵, use K to specify the position of the diagonal. M default None.
In addition, there are several like functions in numpy that create special arrays of the same size according to the size of a known array (several rows and columns). Such functions have Zeros_like (), Empty_like (), Ones_like (), and their arguments are in this form: Zeros_like (a,dtype=), where A is a known array.
Np.l
Np.linspace (1,4,10) #起点, end point, number of points within the interval. The beginning and end points are included. Similarly, there are logspace () functions
Np.linalg.companion (a) # adjoint Matrix
Np.linalg.triu ()/tril () #返回上下triangular matrix
NP.LINALG.LOGM (a) calculates the logarithm of matrix A.
Np.linalg.norm (a,ord=none) #计算矩阵a的Norm
Np.linalg.cond (a,p=none) #矩阵a的condition number
Np.r
Np.random.rand (3,2) #产生一个3行2列的 a random array. in the same space, there are several random functions such as RANDN ()/randint ()
Np.roll (x,2) #roll () is a cyclic shift function. This call represents a 2-bit move to the right loop .
Np.f
FLIPLR ()/flipud ()/rot90 () #左右上下翻转, counterclockwise rotation 90-degree matrix
Np.d
Np.dot (A, b) to calculate the dot product of an array
Np.v
VDOT (A, B) specifically calculates the dot product of the vector, and dot () differs in that the processing of the complex data type is not the same;
#vstack ((a)) two arrays simply fit together #hstack ((b)) Two arrays are combined by each line to Column_stack ((A, B))
A quick look at the NP function of Python small white