numpy.min_scalar_type#

numpy.min_scalar_type(a, /)#

对于标量 a,返回大小最小、标量种类最小且能够容纳其值的数. 对于非标量数组 a,返回未经修改的向量的 dtype.

浮点值不会被降级为整数,复数值也不会被降级为浮点数.

参数:
a标量或 array_like

要查找其最小数据类型的the value.

返回:
outdtype

the minimal data type.

示例

>>> import numpy as np
>>> np.min_scalar_type(10)
dtype('uint8')
>>> np.min_scalar_type(-260)
dtype('int16')
>>> np.min_scalar_type(3.1)
dtype('float16')
>>> np.min_scalar_type(1e50)
dtype('float64')
>>> np.min_scalar_type(np.arange(4,dtype='f8'))
dtype('float64')