您可以跳过底线,如果你不关心背景:如何强制减法在Python中签名?
我在Python下面的代码:
ratio = (point.threshold - self.points[0].value)/(self.points[1].value - self.points[0].value)
这是给我的错误的价值观。例如,对于:
threshold: 25.0
self.points[0].value: 46
self.points[1].value: 21
我:
ratio: -0.000320556853048
哪项是错误的。
寻找到它,我意识到self.points[0].value
和self.points[1].value] are of the type
numpy.uint16`,所以我就:
21 - 46 = 65511
虽然我从来没有为point.threshold
定义的类型。我刚分配它。我想它有一个普通的香草int
。
底线
我怎么能强迫两个uint
S中的减法要签名?
我正在读取数据是uint16格式的二进制文件中的数据。我也从未来导入了真正的分区 – 2009-08-27 18:48:14
但是他们是否需要无符号的,即他们实际上是否在'2 ** 15'和'2 ** 16'之间取值?否则,无符号与有符号整数的二进制格式没有区别。 – 2009-08-28 05:23:38