howto make Python list from numpy.array?

Robert Kern robert.kern at gmail.com
Sun May 6 16:08:24 EDT 2007


Amaury Forgeot d'Arc wrote:
> Hello,
> 
> John Nagle a écrit :
>> dmitrey wrote:
>>> howto make Python list from numpy.array?
>>> Thx, D.
>>>
>> lst = map(None, arr)        // for 1D arrays.
> 
> Which can be expressed more simply as:
>    lst = list(arr)

For N-D arrays, that will give you a list of arrays. If you want a list of lists
(of lists of lists ... etc N times), use the .tolist() method of arrays.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco




More information about the Python-list mailing list