深度学习入门 基于Python的理论与实现

1 Python入门

man.py

class Man:
    def __init__(self, name):
        self.name = name
        print("Initialized!")
        
    def hello(self):
        print("Hello " + self.name + "!")
    
    def goodbye(self):
        print("Good-bye " + self.name + "!")

m = Man("David")
m.hello()
m.goodbye()

sin.py

import numpy as np
import matplotlib.pyplot as plt
# 生成数据
x = np.arange(0, 6, 0.1)
y = np.sin(x)
print(x)
print(y)
# 绘制图形
plt.plot(x,y)
plt.show()

pyplot.py

import numpy as np
import matplotlib.pyplot as plt
# 生成数据
x = np.arange(0, 6, 0.1)
y1 = np.sin(x)
y2 = np.cos(x)
# 绘制图形
plt.plot(x, y1, label="sin")
plt.plot(x, y2, linestyle="--", label="cos")
plt.xlabel("x")
plt.ylabel("y")
plt.title('sin & cos')
plt.legend()
plt.show()

show_image.py

import matplotlib.pyplot as plt
from matplotlib.image import imread
img = imread('avatar_nahida.jpg')   # 任意图片
plt.imshow(img)
plt.show()