หากต้องการทดสอบว่าประเภท float ที่คล้ายกันซึ่งมีขนาดต่างกันนั้นเป็นประเภทย่อยของคลาส float หรือไม่ ให้ใช้วิธี thenumpy.issubdtype() ใน Python Numpy พารามิเตอร์คือ dtype หรือ object coercible toone
ขั้นตอน
ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
import numpy as np
การใช้เมธอด issubdtype() ใน Numpy การตรวจสอบประเภทข้อมูลทศนิยมที่มีขนาดต่างกัน -
print("Result...",np.issubdtype(np.float16, np.floating))
print("Result...",np.issubdtype(np.float32, np.floating))
print("Result...",np.issubdtype(np.float64, np.floating)) ตัวอย่าง
import numpy as np
# To test whether similar float type of different sizes are subdtypes of floating class, 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")
# Checking for floating point datatype with different sizes
print("Result...",np.issubdtype(np.float16, np.floating))
print("Result...",np.issubdtype(np.float32, np.floating))
print("Result...",np.issubdtype(np.float64, np.floating)) ผลลัพธ์
Using the issubdtype() method in Numpy Result... True Result... True Result... True