Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I fill a large array in numpy?

I’m trying to fill an array of size 2 ^ 32 and at a certain stage of filling it gives out that the process was killed

def MakeArr(n):
    start_time = time.time()

    arr = np.random.randint(1, 2**n, size=2**n, dtype=np.int64)

    print(arr)
    print("Time to create: %s sec" % (time.time() - start_time))
    print("arr len:" + str(len(arr)))
    return arr
sys.setrecursionlimit(1500); n = 32; arr = MakeArr(n)

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

An array of 2^32 may be too large for python or numpy to handle. You may be able to get a bigger array by changing the dtype to a lower one, like np.int8.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading