numpy.min_scalar() วิธีค้นหาประเภทข้อมูลขั้นต่ำ พารามิเตอร์ที่ 1 คือค่าที่มีประเภทข้อมูลน้อยที่สุดที่จะพบ สำหรับสเกลาร์ ส่งคืนชนิดข้อมูลด้วยขนาดที่เล็กที่สุดและชนิดสเกลาร์ที่เล็กที่สุดซึ่งสามารถเก็บค่าได้ สำหรับอาร์เรย์ที่ไม่ใช่สเกลาร์ ส่งคืน dtype ของเวคเตอร์ unmodified ค่าจุดลอยตัวจะไม่ถูกลดระดับเป็นจำนวนเต็ม และค่าที่ซับซ้อนจะไม่ถูกลดระดับให้ลอย
ขั้นตอน
ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
import numpy as np
numpy.min_scalar() วิธีค้นหาประเภทข้อมูลขั้นต่ำ -
print("Using the min_scalar() method in Numpy\n")
print("Result...",np.min_scalar_type(55))
print("Result...",np.min_scalar_type(38.9))
print("Result...",np.min_scalar_type(-78))
print("Result...",np.min_scalar_type(479))
print("Result...",np.min_scalar_type(2e100))
print("Result...",np.min_scalar_type(-45.8))
print("Result...",np.min_scalar_type(6.5e100)) ตัวอย่าง
# For scalar, returns the data type with the smallest size and smallest scalar kind which can hold its value.
# For non-scalar array, returns the vector’s dtype unmodified.
# Floating point values are not demoted to integers, and complex values are not demoted to floats.
import numpy as np
# The numpy.min_scalar() method finds the minimal data type.
# The 1st parameter is the value whose minimal data type is to be found.
print("Using the min_scalar() method in Numpy\n")
print("Result...",np.min_scalar_type(55))
print("Result...",np.min_scalar_type(38.9))
print("Result...",np.min_scalar_type(-78))
print("Result...",np.min_scalar_type(479))
print("Result...",np.min_scalar_type(2e100))
print("Result...",np.min_scalar_type(-45.8))
print("Result...",np.min_scalar_type(6.5e100)) ผลลัพธ์
Using the min_scalar() method in Numpy Result... uint8 Result... float16 Result... int8 Result... uint16 Result... float64 Result... float16 Result... float64