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

 

相关文章:

  • 2022-01-06
  • 2021-05-22
  • 2021-12-03
  • 2021-05-04
  • 2021-09-22
  • 2021-11-17
  • 2022-12-23
猜你喜欢
  • 2021-10-01
  • 2021-06-09
  • 2021-12-03
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
相关资源
相似解决方案