【发布时间】:2014-04-19 11:05:59
【问题描述】:
我有一个类似这样的线程(为清楚起见而缩短):
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))
重要的一点是 print 语句中的 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
我做错了什么?
【问题讨论】:
标签: python python-2.7