问题
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