2014-04-19 3 views
0

내가 (명확성을 위해 단축) 이런 식 스레드가에서 발생했습니다RuntimeWarning : 오버 플로우가 ulong_scalars

from __future__ import absolute_import, division, generators, unicode_literals, print_function, nested_scopes, with_statement 
import numpy as np 

g = [] 
def run(self, faces): 
    total = some_stuff_thats_correct() 
    g.append(total) 
    i = 1 
    if len(g) > 1: 
     i += 1 
     g1 = g[len(g)-1] 
     g0 = g[len(g)-2] 
     print(g1, g0, g1 - g0, len(g), type(g1), type(g0)) 

중요한 비트가 인쇄 문에서 G1-G0이다. 실제 출력 아래 다음과

376313 378765 18446744073709549164 2 <type 'numpy.uint64'> <type 'numpy.uint64'> 
374107 376313 18446744073709549410 3 <type 'numpy.uint64'> <type 'numpy.uint64'> 
374661 374107 554 4 <type 'numpy.uint64'> <type 'numpy.uint64'> 
374405 374661 18446744073709551360 5 <type 'numpy.uint64'> <type 'numpy.uint64'> 
375109 374405 704 6 <type 'numpy.uint64'> <type 'numpy.uint64'> 
376084 375109 975 7 <type 'numpy.uint64'> <type 'numpy.uint64'> 
378705 376084 2621 8 <type 'numpy.uint64'> <type 'numpy.uint64'> 
380195 378705 1490 9 <type 'numpy.uint64'> <type 'numpy.uint64'> 
382308 380195 2113 10 <type 'numpy.uint64'> <type 'numpy.uint64'> 
383803 382308 1495 11 <type 'numpy.uint64'> <type 'numpy.uint64'> 
383652 383803 18446744073709551465 12 <type 'numpy.uint64'> <type 'numpy.uint64'> 
384519 383652 867 13 <type 'numpy.uint64'> <type 'numpy.uint64'> 
382326 384519 18446744073709549423 14 <type 'numpy.uint64'> <type 'numpy.uint64'> 
381366 382326 18446744073709550656 15 <type 'numpy.uint64'> <type 'numpy.uint64'> 
378263 381366 18446744073709548513 16 <type 'numpy.uint64'> <type 'numpy.uint64'> 
378094 378263 18446744073709551447 17 <type 'numpy.uint64'> <type 'numpy.uint64'> 

문제 : 세 번째 열은 첫 번째 두 열의 차이되어야

. 때로는 때로는 때로는 그것이 크게 다릅니다. 나는 또한이 경고를 받는다 : RuntimeWarning: overflow encountered in ulong_scalars

내가 뭘 잘못하고 있니?

답변

2

결과가 '부호없는 정수'이므로 문제가 발생합니다. 즉 음수 일 수 없습니다. 정상적인 정수로 변환하면 모든 것이 잘 동작합니다.

관련 문제