【发布时间】:2017-08-27 14:30:49
【问题描述】:
以下 Python 3.6 代码在 Windows 上运行:
print (111111, row [maxMins [deflectionIndex]])
print (222222, row [maxMins [deflectionIndex + 1]])
print (333333, row [maxMins [deflectionIndex]] - row [maxMins [deflectionIndex + 1]])
print (444444, 29697 - -23272)
print (555555, origRow.dtype)
print (666666, type (row [maxMins [deflectionIndex]])
a = row [maxMins [deflectionIndex]]
print (777777, type (a))
其中row是从numpy数组origRow中获取的,如下:
row = [origRow [0]]
for sample in origRow [1:]:
while sample == row [-1]: # Avoid completely flat curve segments, since the max-min algorithm can't deal them
sample += 0.000001 * (ev.random () - 0.5)
row.append (sample)
打印:
111111 29697
222222 -23272
333333 -12567
444444 52969
555555 int16
666666 <class 'numpy.int16'> <class 'numpy.int16'>
777777 <class 'numpy.int16'>
我希望标有 333333 和 444444 的行显示相同的计算结果。
numpy 整数与 Python 整数的处理方式不同吗? 这意味着如果我首先将 numpy 数组元素分配给 Python 变量,语义会发生变化,因为它将被转换为 Python 无限长度整数? [编辑:不!]
很明显,它们存储为 C++ 固定长度整数,因此可以环绕。 但是如果 C++ 整数的数值范围太小,为什么不将它们提升为 Python 整数呢?
【问题讨论】:
-
29697 - -23272这是做什么的?我们可以用+替换它吗? -
它从 29697 中减去 -23272,就像上面那行一样,只是得到了完全不同的结果!
-
好的,知道了。谢谢。
-
行数组的 numpy dtype 是什么?
-
它们没有区别对待,它们是不同的类型。 python 中的赋值不会触发任何转换或提升,它只是将名称绑定到对象。