List to array conversion to use ravel() function


Question

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

1
98
6/29/2019 9:18:43 PM

Accepted Answer

Use numpy.asarray:

import numpy as np
myarray = np.asarray(mylist)
212
2/7/2019 4:26:40 PM

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)

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