numpy.min_scalar() 메소드는 최소 데이터 유형을 찾습니다. 첫 번째 매개변수는 최소 데이터 유형을 찾는 값입니다. 스칼라의 경우 값을 보유할 수 있는 가장 작은 크기와 가장 작은 스칼라 종류를 가진 데이터 유형을 반환합니다. 비 스칼라 배열의 경우 수정되지 않은 벡터의 dtype을 반환합니다. 부동 소수점 값은 정수로 강등되지 않고 복소수 값은 부동 소수점으로 강등되지 않습니다.
단계
먼저 필요한 라이브러리를 가져옵니다 -
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