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


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

numpy.obj2sctype()函數返回對象的標量dtype或等效於NumPy的Python類型。

用法: numpy.obj2sctype(rep, default = None)

參數:
rep:[any]返回類型的對象。
default:[任何,可選]如果給定,則為無法確定類型的對象返回此值。如果未給出,則不為那些對象返回None。
返回:[dtype或Python type]返回rep的數據類型。

代碼1:

# Python program explaining 
# numpy.obj2sctype() function 
           
# importing numpy as geek  
import numpy as geek  
       
gfg = geek.obj2sctype(geek.float64) 
     
print (gfg)

輸出:

class 'numpy.float64'


代碼2:

# Python program explaining 
# numpy.obj2sctype() function 
           
# importing numpy as geek  
import numpy as geek  
       
gfg = geek.obj2sctype(geek.array([1.j])) 
     
print (gfg)

輸出:

class 'numpy.complex128'

相關用法


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