AttributeError with shape command
Hello, I am new to numpy. When I try to use the command array.shape, I get the following error: AttributeError: 'list' object has no attribute 'shape' Is anyone familiar with this type of error? Thanks
On 27.03.2012, at 2:07AM, Stephanie Cooke wrote:
I am new to numpy. When I try to use the command array.shape, I get the following error:
AttributeError: 'list' object has no attribute 'shape'
Is anyone familiar with this type of error?
It means 'array' actually is not one, more precisely, not an object of type np.ndarray. How did you create your array? If it originates just from a list of numbers, you can create an array from it by 'np.array(list)' (assuming previous 'import numpy as np'). It's also possible that a function has returned a list of arrays where you might have expected a single array - so it really depends on the circumstances. HTH, Derek
It means "array" is a regular Python list and not a numpy array. Use numpy.array(array) to convert it into an array. -=- Olivier Le 26 mars 2012 20:07, Stephanie Cooke <cooke.stephanie@gmail.com> a écrit :
Hello,
I am new to numpy. When I try to use the command array.shape, I get the following error:
AttributeError: 'list' object has no attribute 'shape'
Is anyone familiar with this type of error?
Thanks _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
participants (3)
-
Derek Homeier -
Olivier Delalleau -
Stephanie Cooke