입력과 같은 종류의 가장 높은 정밀도의 스칼라 유형을 반환하려면 Python Numpy에서 maximum_sctype() 메서드를 사용합니다. 매개변수는 입력 데이터 유형입니다. 이것은 adtype 개체이거나 dtype으로 변환할 수 있는 개체일 수 있습니다.
단계
먼저 필요한 라이브러리를 가져옵니다 -
import numpy as np
Numpy에서 maximum_sctype() 메서드를 사용합니다. 가장 높은 정밀도의 스칼라 유형 가져오기 -
print("Result...",np.maximum_sctype(int))
print("Result...",np.maximum_sctype(np.uint8))
print("Result...",np.maximum_sctype(complex))
print("Result...",np.maximum_sctype(str))
print("Result...",np.maximum_sctype('f4'))
print("Result...",np.maximum_sctype('i2'))
print("Result...",np.maximum_sctype('i4'))
print("Result...",np.maximum_sctype('i8')) 예시
import numpy as np
# To return the scalar type of highest precision of the same kind as the input, use the maximum_sctype() method in Python Numpy
# The parameter is the input data type. This can be a dtype object or an object that is convertible to a dtype.
print("Using the maximum_sctype() method in Numpy\n")
# Get the scalar type of highest precision
print("Result...",np.maximum_sctype(int))
print("Result...",np.maximum_sctype(np.uint8))
print("Result...",np.maximum_sctype(complex))
print("Result...",np.maximum_sctype(str))
print("Result...",np.maximum_sctype('f4'))
print("Result...",np.maximum_sctype('i2'))
print("Result...",np.maximum_sctype('i4'))
print("Result...",np.maximum_sctype('i8')) 출력
Using the maximum_sctype() method in Numpy Result... <class 'numpy.int64'> Result... <class 'numpy.uint64'> Result... <class 'numpy.complex256'> Result... <class 'numpy.str_'> Result... <class 'numpy.float128'> Result... <class 'numpy.int64'> Result... <class 'numpy.int64'> Result... <class 'numpy.int64'>