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


Python numpy.matlib.empty()用法及代碼示例

numpy.matlib.empty()函數返回給定形狀和類型的新矩陣,而無需初始化條目。

用法: numpy.matlib.empty(shape, dtype = None, order = ‘C’)
參數:
shape :[int or tuple of int] Shape of the empty matrix.
dtype :[data-type, optional] Desired output data-type.
order :[{‘C’, ‘F’}, optional] Whether to store multi-dimensional data in row-major (C-style) or column-major (Fortran-style) order in memory.
Return :[matrix] A new matrix of given shape and type, without initializing entries.

代碼1:

# Python program explaining 
# numpy.matlib.empty() function 
  
# importing numpy as geek  
# and importing matlib module   
import numpy as geek 
import numpy.matlib 
  
# filled with random data 
gfg = geek.matlib.empty((2, 2)) 
  
# output will be random 
print (gfg)

輸出:

[[  6.91957648e-310   1.90383493e-316]
 [  6.91957669e-310   5.30409905e-317]]


代碼2:

# Python program explaining 
# numpy.matlib.empty() function 
  
# importing numpy as geek  
# and importing matlib module   
import numpy as geek 
import numpy.matlib 
  
# filled with random data 
gfg = geek.matlib.empty((2, 2), dtype = int) 
  
# output will be random 
print (gfg)

輸出:

[[139855860099992        40294208]
 [139855825297024        10730496]]

相關用法


注:本文由純淨天空篩選整理自sanjoy_62大神的英文原創作品 numpy.matlib.empty() function | Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。