创建
array1 = np.array([1, 2, 3, 4, 5])array2 = np.arange(0, 20, 2)# 产生10个$[1, 100)$范围的随机整数array5 = np.random.randint(1, 100, 10)array7 = np.array([[1, 2, 3], [4, 5, 6]])array8 = np.zeros((3, 4))array9 = np.ones((3, 4))# 使用eye函数创建单位矩阵array11 = np.eye(4)# 通过reshape将一维数组变成二维数组array12 = np.array([1, 2, 3, 4, 5, 6]).reshape(2, 3)
import matplotlib.pyplot as pltimport numpy as np# 生成数据x = np.arange(0, 6, 0.1) # 以0.1为单位,生成0到6的数据y1 = np.sin(x)y2 = np.cos(x)# 绘制图形plt.plot(x, y1, label="sin")plt.plot(x, y2, linestyle="--", label="cos") # 用虚线绘制plt.xlabel("x") # x轴标签plt.ylabel("y") # y轴标签plt.title('sin & cos') # 标题plt.legend()# 添加图例plt.show()