python--zeros函数和ones函数

使用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.]])
原文地址:https://www.cnblogs.com/chamie/p/4856023.html