Basic knowledge of Python related libraries

1. Detailed usage of numpy.linspace

numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)

Returns evenly spaced numbers within the specified interval.

Return num uniformly distributed samples in [start, stop].

The endpoints of this interval can be excluded arbitrarily.

 

Examples

>>>

>>> np.linspace(2.0, 3.0, num=5)
    array([ 2.  ,  2.25,  2.5 ,  2.75,  3.  ])
>>> np.linspace(2.0, 3.0, num=5, endpoint=False)
    array([ 2. ,  2.2,  2.4,  2.6,  2.8])
>>> np.linspace(2.0, 3.0, num=5, retstep=True)
    (array([ 2.  ,  2.25,  2.5 ,  2.75,  3.  ]), 0.25)

2. The use of asterisk (*) in python, that is, (*train_x.shape)

3. Numpy learning-np.random.randn(), np.random.rand() and np.random.randint()

4. Matplotlib-data visualization plt.plot

How to use plt.legend in matplotlib

plt.plot(x,y,ls,lw,c,marker,markersize,markeredgecolor,markerfacecolor,label)
Set the standard and form of line drawing.
Parameter description:
**x: ** abscissa; **y: ** vertical coordinate;

**ls or linestyle: ** the form of the line ('-','–',':' and'-.');

**lw (or linewidth): ** the width of the line;

**c:** the color of the line;

**marker:** the shape of the point on the line;

**markersize or ms: **marker size, floating point type;

**markerfacecolor: **point fill color;

**markeredgecolor: the edge color of the marker

label: **Text label

 

#Note: The ro below is the format_string parameter in the plot function, r-red, o-filled circle mark

plt.plot(train_X,train_Y,'ro',label ='Original data')#Display simulated data points

5. Python multiple graphs are displayed in different windows at the same time


如下代码所示,首先要为每个图建立一个figure,这样每个图会单独显示在一个窗口中;然后等所有图代码都写好后在最后面加上plt.show(),这样每张图就可以在不同窗口中同时显示了。

————————————————

 # 绘制图1
 plt.figure()
 plt.plot(y, 'b-', linewidth=2)
 plt.legend()
 plt.grid(True)
 
 
 # 绘制图2
 plt.figure()
 plt.plot(z, 'b-', linewidth=2)
 plt.legend()
 plt.grid(True)

————————————————

原文链接:https://blog.csdn.net/sinat_35821976/article/details/84950697

6, python can't write a line

a = 'te' \
'st'

a=('te'
'st')

7. The difference between from...import * statement and import

  • import module : Import a module; Note: It is equivalent to import a folder, which is a relative path.
  • from...import : Import a function in a module; Note: It is equivalent to import a file in a folder, which is an absolute path.

The difference between from...import * statement and import is:

Import  imports a module, and every time you use a function in the module, you must determine which module it is.

from...import *  Import a module. Every time you use a function in the module, you can use the function directly; note that you already know that the function belongs to that module.

8. How to understand if __name__ =='__main__' correctly

9, Python strip() method

Guess you like

Origin blog.csdn.net/sunshine04/article/details/106645028