Converting list of Arrays to list of Lists?

Viewed 23506

After some complex operations, a resultant list is obtained, say list1, which is a list of different arrays.

Following is the list1

In [] : list1
Out [] : 
       [array([ 10.1]),
        array([ 13.26]),
        array([ 11.0 ,  12.5])]

Want to convert this list to simple list of lists and not arrays

Expected list2

      [ [ 10.1],
        [ 13.26],
        [ 11.0 ,  12.5] ]

Please let me know if anything is unclear.

6 Answers

If you have more than 1D list, say 2D or more, you can use this to make all entries in just one list, I found it online but don't remember from whom did I take it xD

dummy = myList.tolist()
flatten = lambda lst: [lst] if type(lst) is int else reduce(add, [flatten(ele) for ele in lst])
points = flatten(dummy)

You will get a list of all points or all entries.

I have tested on this list

[[[3599, 532]], [[5005, 493]], [[4359, 2137]]]

and here is the output

[3599, 532, 5005, 493, 4359, 2137]
Related