📜  numpy 矩阵运算 | zeros()函数

📅  最后修改于: 2022-05-13 01:55:49.279000             🧑  作者: Mango

numpy 矩阵运算 | zeros()函数

numpy.matlib.zeros()是另一个在 numpy 中进行矩阵运算的函数。它返回一个给定形状和类型的矩阵,用零填充。

代码#1:

# Python program explaining
# numpy.matlib.zeros() function
  
# importing matrix library from numpy
import numpy as geek
import numpy.matlib
  
# desired 3 x 4 zero output matrix 
out_mat = geek.matlib.zeros((3, 4)) 
print ("Output matrix : ", out_mat) 
输出 :
Output matrix :  [[ 0.  0.  0.  0.]
 [ 0.  0.  0.  0.]
 [ 0.  0.  0.  0.]]

代码#2:

# Python program explaining
# numpy.matlib.zeros() function
  
# importing numpy and matrix library
import numpy as geek
import numpy.matlib
  
# desired 1 x 5 zero output matrix 
out_mat = geek.matlib.zeros(shape = 5, dtype = int) 
print ("Output matrix : ", out_mat) 
输出 :
Output matrix :  [[0 0 0 0 0]]