Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 被数据类型转换为np弄糊涂了。float16值2053变为2052_Python_Pandas_Numpy - Fatal编程技术网

Python 被数据类型转换为np弄糊涂了。float16值2053变为2052

Python 被数据类型转换为np弄糊涂了。float16值2053变为2052,python,pandas,numpy,Python,Pandas,Numpy,我试图通过向下转换浮点数据类型来减少内存消耗 我检查了np.float16的范围: np.finfo(np.float16) finfo(resolution=0.001, min=-6.55040e+04, max=6.55040e+04, dtype=float16) 这显示-6.55040e+04

我试图通过向下转换浮点数据类型来减少内存消耗

我检查了
np.float16的范围:

np.finfo(np.float16)
finfo(resolution=0.001, min=-6.55040e+04, max=6.55040e+04, dtype=float16)
这显示
-6.55040e+04<2053<6.55040e+04

现在:

s=pd.系列([2051205220532054])
s、 aType(np.16)
0    2052.0
1    2052.0
2    2052.0
3    2054.0
为什么会这样

更新
np.finfo

numpy.finfo
class numpy.finfo[source]
Machine limits for floating point types.

Parameters: 
dtype : float, dtype, or instance

Kind of floating point data-type about which to get information.

Attributes

eps (float) The smallest representable positive number such that 1.0 + eps != 1.0. Type of eps is an appropriate floating point type.
epsneg  (floating point number of the appropriate type) The smallest representable positive number such that 1.0 - epsneg != 1.0.
iexp    (int) The number of bits in the exponent portion of the floating point representation.
machar  (MachAr) The object which calculated these parameters and holds more detailed information.
machep  (int) The exponent that yields eps.
max (floating point number of the appropriate type) The largest representable number.
maxexp  (int) The smallest positive power of the base (2) that causes overflow.
min (floating point number of the appropriate type) The smallest representable number, typically -max.
minexp  (int) The most negative power of the base (2) consistent with there being no leading 0’s in the mantissa.
negep   (int) The exponent that yields epsneg.
nexp    (int) The number of bits in the exponent including its sign and bias.
nmant   (int) The number of bits in the mantissa.
precision   (int) The approximate number of decimal digits to which this kind of float is precise.
resolution  (floating point number of the appropriate type) The approximate decimal resolution of this type, i.e., 10**-precision.
tiny    (float) The smallest positive usable number. Type of tiny is an appropriate floating point type.

它不是关于
min
max
,它们决定了
float16
可以分别取的最低值和最高值,而是
分辨率
,或者两个值在被认为相同之前的最小差值


finfo
显示
float16
的分辨率为
0.001
,或4位有效数字。您案例中的数字
2
是第四个有效数字。

那么,如何找到
np.float16
支持的最大/最小值?检查和设置数据类型会更容易?
finfo
报告的值是准确的。这里的问题不是您的值太高或太低,而是您没有足够的位来区分两个“附近”的值。这意味着np.float16不能用于任何超过3个整数的值?i、 e.适用于xxx,但不适用于xxxx,这还取决于您的数字的绝对值。不过,一般来说,对于大多数
pandas
工作,我不建议使用
float16
。你真的那么缺乏内存吗?不,我的macpro上有16GB的RAM,我只是在处理1GB的数据集,内存不是问题,但是我被
np.finfo
的文档弄糊涂了,我想在你有能力的时候保存内存会更好。也许我应该在numpy github中创建一个问题。