zeros()和ones()和eye()

时间:2023-03-09 05:59:11
zeros()和ones()和eye()

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