Skip to content Skip to sidebar Skip to footer

Memory Error In Instantiating The Numpy Array

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 MemoryErr

Solution 1:

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

Solution 2:

As a workaround, you could avoid copying the arrays with something like:

B = np.empty(len(A), dtype=object)
for i, a inenumerate(A):
    B[i] = a

This would allow to create a ndarray of dtype object whose elements would be the original elements of A. You could then perform some array operations on it.

But I am not sure you have something to win in going this way.

Post a Comment for "Memory Error In Instantiating The Numpy Array"