Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List to array conversion to use ravel() function

I have a list in python and I want to convert it to an array to be able to use ravel() function.

like image 525
user2229953 Avatar asked Apr 07 '13 22:04

user2229953


People also ask

How do you turn a list into an array?

To convert a list to array in Python, use the np. array() method. The np. array() is a numpy library function that takes a list as an argument and returns an array containing all the list elements.

Which function can be used to convert an array into a list?

We can use numpy ndarray tolist() function to convert the array to a list.


2 Answers

Use numpy.asarray:

import numpy as np myarray = np.asarray(mylist) 
like image 55
A. Rodas Avatar answered Oct 19 '22 07:10

A. Rodas


create an int array and a list

from array import array listA = list(range(0,50)) for item in listA:     print(item) arrayA = array("i", listA) for item in arrayA:     print(item) 
like image 39
Uszkai Attila Avatar answered Oct 19 '22 07:10

Uszkai Attila