howto make Python list from numpy.array?
dmitrey
openopt at ukr.net
Sun May 6 16:06:56 EDT 2007
Thanks all.
I tried all the approaches but they don't work in my situation
I have a variable x that can be
x = 1
x = [1, 2, 3]
x = numpy.array([1,2,3])
so all troubles are with 1st case
>>> x=1
>>> list(x)
Traceback (most recent call last):
File "<string>", line 1, in <string>
TypeError: iteration over non-sequence
>>> list(array(1))
Traceback (most recent call last):
File "<string>", line 1, in <string>
ValueError: Rank-0 array has no length.
>>> array(1).tolist()
Traceback (most recent call last):
File "<string>", line 1, in <string>
ValueError: rank-0 arrays don't convert to lists.
>>>
Here I used Python 2.4.3, numpy 1.02
More information about the Python-list
mailing list