python—zeros函数和ones函数

时间:2015-10-05 18:13:33   收藏:0   阅读:3110

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

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!