當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。