How to save a list as numpy array in python?

Hossein picture Hossein · May 10, 2011 · Viewed 279.3k times · Source

Is possible to construct a NumPy array from a python list?

Answer

Bryce Siedschlaw picture Bryce Siedschlaw · May 10, 2011

First of all, I'd recommend you to go through NumPy's Quickstart tutorial, which will probably help with these basic questions.

You can directly create an array from a list as:

import numpy as np
a = np.array( [2,3,4] )

Or from a from a nested list in the same way:

import numpy as np
a = np.array( [[2,3,4], [3,4,5]] )