1

I got the following error

MemoryError: Unable to allocate 201. GiB for an array with shape (2999, 2999, 2999) and data type int64

when creating a meshgrid with Numpy using the following code

dimension=3
tot_length=2000
list_no=range(1, tot_length)
arr = np.meshgrid ( *[list_no for _ in range ( dimension )] )

May I know where to change the int64 to int32 or, other possible setting that can allow me to maximize the number of tot_length which is higher than the value 2000

I have check the documentation, but it does not stated option to change the data type to type32.

2
  • What is rows on line 3? your code only defines rows_1? Commented Oct 20, 2020 at 15:58
  • Hi Eric, I have updated the variable name for clarity Commented Oct 20, 2020 at 15:59

1 Answer 1

1

May I know where to change the int64 to int32

NumPy is guessing int64 because you are giving it a range object where it expects an array, and ranges are sequences of int. Use an array if you want it not to guess:

list_no = np.array(range(1, tot_length), dtype=np.int32)

or more simply

list_no = np.arange(1, tot_length, dtype=np.int32)

Of course, you'll still need 100 GiB of memory, which is still quite large.

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

2 Comments

Yes, 100 Gb is still large. Thanks for the insight
Hi Eric, regarding the memory issue, appreciate if you can offer some insight here: stackoverflow.com/q/64450286/6446053

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.