Fix Python – How to save a list as numpy array in python?

Question

Asked By – Hossein

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

Now we will see solution for issue: How to save a list as numpy array in python?


Answer

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]] )

This question is answered By – Bryce Siedschlaw

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0