0

I have this code in python:

from numpy import *
import itertools

m, n  = 6, 10
set_m = [i + 1 for i in range(m + 1)]
comb  = zeros(((m + 1) ** n, n), dtype=int)

k = 0
for i in itertools.product(set_m, repeat=n):
    comb[k][:] = i
    k += 1

But when I run it, I got this error:

Traceback (most recent call last):
  File "main.py", line 33, in <module>
    comb = zeros(((m + 1) ** n, n), dtype=int)
ValueError: array is too big.
4
  • 1
    Just to make sure, you really want 2 billion elements, ((m + 1) ** n)*n? Commented May 25, 2015 at 15:00
  • Yes, sure. You are trying to create an array of integers with size (282475249, 10), which not surprisingly is too big. Commented May 25, 2015 at 15:00
  • 1
    Are you using the 64 bit version of Python? How much memory does your machine have? Commented May 25, 2015 at 15:21
  • 1
    I have python 32 bit and I have 16GB of memory. Commented May 25, 2015 at 15:31

1 Answer 1

4

If you are sure you MUST have a billion element array, and there is no way around it whatsoever (sometimes happens, but not every day), you can use memmap to create the array in the hard drive instead of the RAM memory. But I think it would be wise to search for ways to re-write your code to avoid doing such a slow thing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.