Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the maximum size of a numpy array?

I'm trying to create a matrix containing 2 708 000 000 elements. When I try to create a numpy array of this size it gives me a value error. Is there any way I can increase the maximum array size?

a=np.arange(2708000000)

ValueError Traceback (most recent call last)

ValueError: Maximum allowed size exceeded

like image 285
branwen85 Avatar asked Jan 25 '13 15:01

branwen85


People also ask

What is the maximum array size in Python?

According to the source code, the maximum size of a list is PY_SSIZE_T_MAX/sizeof(PyObject*) . On a regular 32bit system, this is (4294967295 / 2) / 4 or 536870912. Therefore the maximum size of a python list on a 32 bit system is 536,870,912 elements.

What is size of array in NumPy?

Size of the first dimension of the NumPy array: len() ndarray , len() returns the size of the first dimension. Equivalent to shape[0] and also equal to size only for one-dimensional arrays.

What is the maximum size of an array?

The maximum allowable array size is 65,536 bytes (64K). Reduce the array size to 65,536 bytes or less. The size is calculated as (number of elements) * (size of each element in bytes).

What is NumPy maximum?

maximum() function is used to find the element-wise maximum of array elements. It compares two arrays and returns a new array containing the element-wise maxima. If one of the elements being compared is a NaN, then that element is returned. If both elements are NaNs then the first is returned.


1 Answers

You're trying to create an array with 2.7 billion entries. If you're running 64-bit numpy, at 8 bytes per entry, that would be 20 GB in all.

So almost certainly you just ran out of memory on your machine. There is no general maximum array size in numpy.

like image 118
shoyer Avatar answered Oct 11 '22 17:10

shoyer