如果第一個引數在 Python 中的型別層次結構中是低於/與型別程式碼相同的,則返回 True
若要返回 true,當第一個引數在型別層次結構中是型別程式碼較小/相等時,可在 Python Numpy 中使用 numpy.issubdtype() 方法。引數是資料型別或可強制轉換為資料型別的一個物件。
步驟
首先,匯入所需的庫 −
import numpy as np
在 Numpy 中使用 issubdtype() 方法 −
print("Result...",np.issubdtype(np.float64, np.float32))
print("Result...",np.issubdtype(np.float64, np.floating))
print("Result...",np.issubdtype(np.float32, np.floating))
print("Result...",np.issubdtype('i4', np.signedinteger))
print("Result...",np.issubdtype('i8', np.signedinteger))
print("Result...",np.issubdtype(np.int32, np.integer))示例
import numpy as np
# To return True if first argument is a typecode lower/equal in type hierarchy, use the numpy.issubdtype() method in Python Numpy.
# The parameters are the dtype or object coercible to one
print("Using the issubdtype() method in Numpy\n")
print("Result...",np.issubdtype(np.float64, np.float32))
print("Result...",np.issubdtype(np.float64, np.floating))
print("Result...",np.issubdtype(np.float32, np.floating))
print("Result...",np.issubdtype('i4', np.signedinteger))
print("Result...",np.issubdtype('i8', np.signedinteger))
print("Result...",np.issubdtype(np.int32, np.integer))輸出
Using the issubdtype() method in Numpy Result... False Result... True Result... True Result... True Result... True Result... True
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP