使用numpy.zeros,numpy.ones,numpy.eye等方法可以构造特定的矩阵

例如:

代码如下:

>>>from numpy import *
>>> a=zeros((3,4))
>>> a
array([[ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.]])
>>> from numpy import *
>>> a=ones((3,4))
>>> a
array([[ 1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.]])
>>> from numpy import *
>>> a=eye(3)
>>> a
array([[ 1.,  0.,  0.],
       [ 0.,  1.,  0.],
       [ 0.,  0.,  1.]])

 

posted on 2015-10-05 17:49  chamie  阅读(19709)  评论(0编辑  收藏  举报