如果将其设为只读,则可以简单地对基础缓冲区进行哈希处理:
>>> a = random.randint(10, 100, 100000)>>> a.flags.writeable = False>>> %timeit hash(a.data)100 loops, best of 3: 2.01 ms per loop>>> %timeit hash(a.tostring())100 loops, best of 3: 2.28 ms per loop
对于非常大的阵列,
hash(str(a))速度要快得多,但随后只考虑了阵列的一小部分。
>>> %timeit hash(str(a))10000 loops, best of 3: 55.5 us per loop>>> str(a)'[63 30 33 ..., 96 25 60]'
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)