Python2 语法随笔记录集

1.基本API部分

PRO1. python2生成矩阵Matrix语法

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.]])

  

PRO2. Matplotlib作图

一次生成多个子图,获取每个子图的对象,可以使用add_subplot。

axe4 = plt.add_subplot(234) 表示将图分成了2行3列(也就是一共6个子图了),同时,对象axe4表示是第4张图对应的对象。

详细参考:https://blog.csdn.net/zahuopuboss/article/details/54895890

猜你喜欢

转载自www.cnblogs.com/natty-sky/p/11256337.html
今日推荐