Convert list to array for using ravel () function

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

+96
python arrays list numpy
Apr 07 '13 at 22:17
source share
7 answers

Use numpy.asarray :

 import numpy as np myarray = np.asarray(mylist) 
+205
Apr 7 '13 at 22:20
source share

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) 
+6
Dec 05 '17 at 10:09 on
source share

I need a way to do this without using an additional module. First go to the line, then add to the array:

 dataset_list = ''.join(input_list) dataset_array = [] for item in dataset_list.split(';'): # comma, or other dataset_array.append(item) 
+5
Jan 12 '17 at 22:22
source share

I didn’t succeed, I ended up with an array of lists

0
Apr 03 '19 at 15:45
source share

If all you need is to call ravel on your list (nested, I want?), You can do it directly, numpy will cast for you:

 L = [[1,None,3],["The", "quick", object]] np.ravel(L) # array([1, None, 3, 'The', 'quick', <class 'object'>], dtype=object) 

It's also worth mentioning that you don't need to go through numpy at all .

0
Jun 30 '19 at 1:41
source share

Use the following code:

 import numpy as np myArray=np.array([1,2,4]) #func used to convert [1,2,3] list into an array print(myArray) 
-one
Jun 10 '19 at 18:40
source share

if the variable b has a list, you can simply do the following:

create a new variable "a" as: a=[] then assign the list "a" as: a=b

now "a" has all the components of the list "b" in the array.

so that you successfully convert the list to an array.

-fourteen
Nov 09 '15 at 23:01
source share



All Articles