How to save a list as numpy array in python?


Question

I need to know if it is possible to save a python list as a numPy array.

1
110
5/10/2011 1:51:38 PM

Accepted Answer

If you look here, it might tell you what you need to know.

http://www.scipy.org/Tentative_NumPy_Tutorial#head-d3f8e5fe9b903f3c3b2a5c0dfceb60d71602cf93

Basically, you can create an array from a sequence.

from numpy import array
a = array( [2,3,4] )

Or from a sequence of sequences.

from numpy import array
a = array( [[2,3,4], [3,4,5]] )
141
5/10/2011 3:24:01 PM

you mean something like this ?

from numpy  import array
a = array( your_list )

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon