numpy.matlib.zeros()函数| Python
numpy.matlib.zeros()
函数返回给定形状和类型的矩阵,用零填充。
Syntax : numpy.matlib.zeros(shape, dtype = None, order = ‘C’)
Parameters :
shape : [sequence of ints] Shape of the empty matrix.
dtype : [data-type, optional] The desired data-type for the matrix, default is float.
order : [{‘C’, ‘F’}, optional] Whether to store the result in C- or Fortran-contiguous order, default is ‘C’.
Return : [matrix] Zero matrix of given shape, dtype, and order.
代码#1:
# Python program explaining
# numpy.matlib.zeros() function
# importing numpy as geek
# and importing matlib module
import numpy as geek
import numpy.matlib
gfg = geek.matlib.zeros((3, 3))
print (gfg)
输出 :
[[ 0. 0. 0.]
[ 0. 0. 0.]
[ 0. 0. 0.]]
代码#2:
# Python program explaining
# numpy.matlib.zeros() function
# importing numpy as geek
# and importing matlib module
import numpy as geek
import numpy.matlib
gfg = geek.matlib.zeros(4)
print (gfg)
输出 :
[[ 0. 0. 0. 0.]]