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.
Steps
At first, import the required library −
import numpy as np
Using the maximum_sctype() method in Numpy. 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'))Example
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'))Output
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'>