Memory error In instantiating the numpy array

2024/11/19 9:26:40

I have a list A of a 50,000 elements and each element is an array of shape (102400)

I tried instantiating an array B.

     B=numpy.array(A)

But this throws an exception MemoryError.I know that the memory and size is very huge?But is there a way to avoid this MemoryError with ndarrays in numpy ??

Answer

Assuming they are int64 (the default numpy type). Each occupies 8 bytes, then: The dimensions by the amount of bytes that occupy each one:

50000 * 102400 * 8 = 40960000000

In gigabytes

50000 * 102400 * 8 / 1024**3 = 38.14697265625 Gb
https://en.xdnf.cn/q/118559.html

Related Q&A

Setting column names in a pandas dataframe (Python)

When setting a column name for a pandas dataframe, why does the following work:df_coeff = pd.DataFrame(data = lm.coef_, index = X.columns, columns = [Coefficient])While this does not workdf_coeff = pd.…

Check that Python function does not modify argument?

You know how in Python, if v is a list or a dictionary, its quite common to write functions that modify v in place (instead of just returning the new value). Im wondering if it is possible to write a c…

What Python 3 version for my Django project

I will try to port my Python 2.7 with Django to Python 3. But now my question is what version is the most stable one today? Ive heard people use 3.2 and 3.4 and recommend it. But now Im asking you guy…

Error during runfile in Eclipse with PyDev/ error initializing console

Using a PyDev console in Eclipse, which initially worked fine. Python code would work inside the console. When I started writing a file within a PyDev module, I tried executing runfile() but the consol…

Reversibly encode two large integers of different bit lengths into one integer

I want to encode two large integers of possibly different maximum bit lengths into a single integer. The first integer is signed (can be negative) whereas the second is unsigned (always non-negative). …

Pytube AttributeError: NoneType object has no attribute span

Hi I have a problem with AttributeError: NoneType object has no attribute span I read on the StackOverflow a channel with this problem on this I found the potential solution but it still not working he…

GDB: ModuleNotFoundError: No module named _tkinter [duplicate]

This question already has answers here:Why does tkinter (or turtle) seem to be missing or broken? Shouldnt it be part of the standard library?(4 answers)Closed last year.So Im trying to debug my C co…

Why can the difference of different floating numbers be 0 in python? [duplicate]

This question already has answers here:Float to Int type conversion in Python for large integers/numbers(2 answers)Closed last year.Why is the result of below code 0 in python3? a = "4.1512940685…

twinx and sns.barplot seaborn are overlapping bars

I would like to use sns.seaborn to display the np.sum and the np.mean on 2 different axes (with ax2 = ax1.twinx() I assume). The probem I have is that the graphs are overlapped and not readable.Am I ap…

Cant get tensorflow on Anaconda [duplicate]

This question already has an answer here:TensorFlow Importing error ( Using Anaconda)(1 answer)Closed 2 years ago.I need tensorflow to run a guided project I did on Coursera, but I am not able to insta…