1.tile (A,res) repeats the array, tile (Matrix, (M,n)), extending it to any line
2.shape[0] The number of dimensions of the array,
3.sum (axis=0) adds the columns corresponding to the array, Axis=1, and adds the corresponding rows.
4.argsort (x,axis=0) sorts the array x in ascending order by column, and X for-X. Indicates descending sort by column. X.argsort (), gets the address on its original data
5. For the dictionary get function Dict.get (word,d) If Word returns in the dictionary is word, no
6. Divide the dictionary into Dict.iteritems ();
Operator.itemgetter (1) Gets the data of which dimension of the object, the parameter is some ordinal number (i.e. the ordinal number of the data that needs to be fetched in the object), see the example below.
1A = [A.] 2>>> B=operator.itemgetter (1)//define function B to get the value of the 1th field of an object3>>>B (a)425>>> B=operator.itemgetter (1,0)//define function B, get the 1th field and the No. 0 value of an object6>>>B (a)7(2, 1)8 9 Note that the Operator.itemgetter function does not get a value, but instead defines a function that acts on the object to get the value. Ten One sorted function APython's built-in sorting function sorted can be sorted by list or iterator, as shown on the official website:
7.scatter Drawing scatter Plot code:
1. Draw a vertical chart:
1 ImportNumPy as NP2 fromMatplotlibImportPyplot as Plt3Plt.figure (figsize= (9,6))4n = 85X = Np.arange (n) +16 #x is 1,2,3,4,5,6,7,8, number of bars7 #Numpy.random.uniform (low=0.0, high=1.0, Size=none), normal8 #uniform evenly distributed random number, normal is a normal distribution of random numbers, 0.5-1 evenly distributed number, total n9Y1 = Np.random.uniform (0.5,1.0, N)TenY2 = Np.random.uniform (0.5,1.0, N) OnePlt.bar (x,y1,width = 0.35,facecolor ='Lightskyblue', Edgecolor =' White') A #width: Height of column -Plt.bar (x+0.35,y2,width = 0.35,facecolor ='Yellowgreen', Edgecolor =' White') - #Horizontal Histogram Plt.barh, the width of the property becomes height the #use + when playing two sets of data - #the color of the fill in the Facecolor column chart - #Edgecolor is the color of the border - #want to hit a set of data below, use the minus sign before the data + #Plt.bar (X,-y2, Width=width, facecolor= ' #ff9999 ', edgecolor= ' white ') - #to Tomoo text + forX, yinchZip (x,y1): APlt.text (x+0.3, y+0.05,'%.2f'% y, ha='Center', va='Bottom') at - forX, yinchZip (x,y2): -Plt.text (x+0.6, y+0.05,'%.2f'% y, ha='Center', va='Bottom') -Plt.ylim (0,+1.25) -Plt.show ()
Draw Scatter Plot:
1Plt.figure (figsize= (9,6))2n=10003 #Rand uniform distribution and RANDN Gaussian distribution4X=NP.RANDOM.RANDN (1, N)5Y=NP.RANDOM.RANDN (1, N)6t=np.arctan2 (x, y)7Plt.scatter (x,y,c=t,s=25,alpha=0.4,marker='o')8 #T: The color of the scatter point9 #S: The size of the scatter pointTen #Alpha: The degree of transparency OnePlt.show ()
Scatter (X,y,colro1,color2) Description of two different colors and sizes
9.min function, matrix.min (0) Gets the smallest value in each column, resulting in a sequence of results
10. Using open (' filename ') appears typeerror:file () argument 1 must be encoded string without NULL bytes, the problem of not STR is discussed in two cases
Error when same usage: in multi-level directory descent \ \ \ translate character processing
So, if the read file is placed in the first level file directory, there are two ways to solve the problem:
(1) Change the name of the file to be made up of English letters
(2) the \ character in the pathname is escaped, that is, F:\PythonProject\0_2.txt turns into f:\\pythonproject\\0_2.txt
11.realines vs ReadLine ():
ReadLines reads all lines Readlines.strip (). Split ()---read each word, ReadLine () a row of rows, and each word is divided into the smallest letter
12.numpy the array array multiplication is not the same as matrix multiplication under NumPy
For arrays array:
1 a=array ([2] ) b=ones ((3,1) ) 3 print A, b
Multiplies a array of arrays with each element of the B array to form an array of 3*3; for a matrix, 1*3*3*1 is finally a real number.
[1.2. 6.8
[1.2. 6.8
[1.2. 3.]
NumPy function Usage