numpy包的zeros,ones,eye方法可以实现功能,看下边的例子:
它们分别是0矩阵,1矩阵 和单位阵
>>> np.zeros((5,6)) array([[0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0.]]) >>> np.ones((5,6)) array([[1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1.]]) >>> np.eye(5) array([[1., 0., 0., 0., 0.], [0., 1., 0., 0., 0.], [0., 0., 1., 0., 0.], [0., 0., 0., 1., 0.], [0., 0., 0., 0., 1.]])
一次生成多个子图,获取每个子图的对象,可以使用add_subplot。
axe4 = plt.add_subplot(234) 表示将图分成了2行3列(也就是一共6个子图了),同时,对象axe4表示是第4张图对应的对象。
详细参考:https://blog.csdn.net/zahuopuboss/article/details/54895890
原文:https://www.cnblogs.com/natty-sky/p/11256337.html