How do I convert a NumPy array to a Python List (for example [[1,2,3],[4,5,6]]
), and do it reasonably fast?
Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up
Join them; it only takes a minute:
|
Use
|
||||
|
NumPy arrays have a tolist method:
|
||||
|
The numpy .tolist method produces nested arrays if the numpy array shape is 2D. if flat lists are desired, the method below works.
|
|||
|
You can also use the list keyword of Python to create a list from the numpy array:
|
|||
|