To convert a list into a numpy array in Python, you just need to use the array()
function from the numpy module.
Here is an example:
main.py93 chars8 lines
Output:
main.py12 chars2 lines
In this example, we first import the numpy
module and then define a simple list called my_list
. We then use the array()
function to create a numpy array from the list and assign it to a new variable called my_array
. Finally, we print out the contents of the my_array
variable to verify that the array was created correctly.
Note that the elements in the list must be of the same type for the conversion to work correctly.
gistlibby LogSnag