以下Python 3.6代碼運行在Windows:Numpy/C++整數不提升爲Python整數?
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'這是幹什麼的?我們可以用'+'替換它嗎? – akp
它從29697中減去-23272,就像上面的行一樣,只有一個完全不同的結果! –
好吧。謝謝。 – akp