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)