当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python numpy.matlib.zeros()用法及代码示例


numpy.matlib.zeros()函数返回给定形状和类型的矩阵,并用零填充。

用法: numpy.matlib.zeros(shape, dtype = None, order = ‘C’)
参数:
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.]]

相关用法


注:本文由纯净天空筛选整理自sanjoy_62大神的英文原创作品 numpy.matlib.zeros() function | Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。