I'm creating a couple of arrays using numpy and list constructors, and I can't figure out why this is failing. My code is:
import numpy as np
A = np.ndarray( [i for i in range(10)] ) # works fine
B = np.ndarray( [i**2 for i in range(10)] ) # fails, with MemoryError
I've also tried just B = [i**2 for i in range(10)] which works, but I need it to be an ndarray. I don't see why the normal constructor would work but calling a function wouldn't. As far as I understand, the ndarray constructor shouldn't even see the inside of that, it should get a length 10 list with ints in it for both.
np.array([...]).np.ndarrayis an advanced constructor with different parameters.np.arrayis the one we normally use.np.zeros(oronesorempty) if trying to create an array with a list of dimensions.np.array()to create a new array from a list. The first argument ofndarrayis the shape of the array, not the data to put in the array. So you are requesting an array with shape[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]. It is interesting that it generates aMemoryError. With that 0 in there, the total size of the array would actually be 0.