IndexError on huge list in Python

主宰稳场 提交于 2019-12-25 14:16:15

问题


Handling a list product of 100x100 size is fine in python:

>>> import itertools
>>> import numpy as numpy
>>> nested_loop_iter = itertools.product(range(100), range(100))
>>> probs = np.fromiter(map(lambda x: x[0] *x[1], nested_loop_iter), dtype=int)
>>> probs
array([   0,    0,    0, ..., 9603, 9702, 9801])

But when the size of the list product grows to 100,000 x 100,000, it throws an IndexError:

>>> import itertools
>>> import numpy as numpy
>>> nested_loop_iter = itertools.product(range(100000), range(100000))
>>> probs = np.fromiter(map(lambda x: x[0] *x[1], nested_loop_iter), dtype=int)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list assignment index out of range

Can Python handle such a huge list product? It sums up to 10,000,000,000 elements in the resulting list.

According to this: How Big can a Python Array Get? , Python should be able to handle a list of 10,000,000,000, but why is it still throwing an IndexError?

来源:https://stackoverflow.com/questions/40714519/indexerror-on-huge-list-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!