How do I convert a NumPy array to a Python array_like structure (for example [[1,2,3],[4,5,6]] ), and do it reasonably fast?
+6
A:
Use tolist()
:
import numpy as np
>>> np.array([[1,2,3],[4,5,6]]).tolist()
[[1, 2, 3], [4, 5, 6]]
Peter Hansen
2009-12-27 15:31:19
+4
A:
NumPy arrays have a tolist method:
In [1]: arr=np.array([[1,2,3],[4,5,6]])
In [2]: arr.tolist()
Out[2]: [[1, 2, 3], [4, 5, 6]]
unutbu
2009-12-27 15:32:33