確定給定物件是否表示 Python 中的標量資料型別
要確定給定物件是否表示標量資料型別,請使用 numpy.issctype() 方法。該方法返回檢查 rep 是否為標量資料型別的布林結果。第一個引數是 rep。如果 rep 是標量資料型別的例項,則返回 True。如果不是,則返回 False。
步驟
首先,匯入所需的庫,如下所示:
import numpy as np
在 Numpy 中使用 issctype() 方法,如下所示:
print("Result...",np.issctype(np.int32))
print("Result...",np.issctype(np.int64))
print("Result...",np.issctype(np.dtype('str')))
print("Result...",np.issctype(100))
print("Result...",np.issctype(25.9))
print("Result...",np.issctype(np.float32(22.3)))示例
import numpy as np
# To determine whether the given object represents a scalar datatype, use the numpy.issctype() method
# The method returns Boolean result of check whether rep is a scalar dtype.
# The first parameter is the rep. If rep is an instance of a scalar dtype, True is returned.If not, False is returned.
print("Using the issctype() method in Numpy\n")
print("Result...",np.issctype(np.int32))
print("Result...",np.issctype(np.int64))
print("Result...",np.issctype(np.dtype('str')))
print("Result...",np.issctype(100))
print("Result...",np.issctype(25.9))
print("Result...",np.issctype(np.float32(22.3)))輸出
Using the issctype() method in Numpy Result... True Result... True Result... True Result... False Result... False Result... False
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP