zeros()和ones()和eye()

python--zeros函数和ones函数

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

 1 >>>from numpy import *
 2 >>> a=zeros((3,4))
 3 >>> a
 4 array([[ 0.,  0.,  0.,  0.],
 5        [ 0.,  0.,  0.,  0.],
 6        [ 0.,  0.,  0.,  0.]])
 7 
 8 >>> from numpy import *
 9 >>> a=ones((3,4))
10 >>> a
11 array([[ 1.,  1.,  1.,  1.],
12        [ 1.,  1.,  1.,  1.],
13        [ 1.,  1.,  1.,  1.]])
14 
15 >>> from numpy import *
16 >>> a=eye(3)
17 >>> a
18 array([[ 1.,  0.,  0.],
19        [ 0.,  1.,  0.],
20        [ 0.,  0.,  1.]])
原文地址:https://www.cnblogs.com/sbclmy/p/9717016.html