2
为什么答案是浮点数?我认为它应该是一个整数。无符号和有符号数的numpy总和成为浮点数
>>> import numpy as np
>>> np.uint64(12)
12
>>> np.uint64(12) + int(4)
16.0
>>>
为什么答案是浮点数?我认为它应该是一个整数。无符号和有符号数的numpy总和成为浮点数
>>> import numpy as np
>>> np.uint64(12)
12
>>> np.uint64(12) + int(4)
16.0
>>>
根据最近的reddit post。
这是Numpy函数设计用于为整个输入数据范围返回一致值的方式。
16位无符号和符号整数将融入INT32,因此
>>> np.uint16(4) + np.int16(5)
9
然而,对于UINT64和Int64的,将适合所有可能的值最小的数据类型是float64。
这肯定是出乎意料的。 –
那么,至少结果与'np.promote_types(np.uint64,np.int)'一致。我在github上发现了一个[相关问题](https://github.com/numpy/numpy/issues/5745) –