How to convert result multidimentional list python to single list python

I have result value of some training data like this

 [[        0]
 [         0]
 [         0]
 [1049.3618 ]
 [1049.3618 ]
 [1049.3618 ]
 [1047.8524 ]
 [1034.0015 ]
 [1011.92944]
 [ 997.6305 ]
 [ 985.61743]
 [ 971.35583]
 [ 953.3492 ]
 [ 934.00104]
 [ 912.93585]
 [ 886.3636 ]
 [ 857.08594]
 [ 832.37103]
 [ 803.3781 ]
 [ 775.04083]]

How to convert the value to normal array in python like this? and how to remove nan values with 0?
This is the result that I want

[0,0,0,1049.3618,1049.3618,1049.3618,1047.8524]

>Solution :

The array can be converted to list using tolist() which will result to list of lists e.g.:[[1,2,3], [2,3,4], [0]].

[x for sub_list in  <your_array>.tolist() for x in sub_list]

The array can also be flattened to a list using array.flatten(). More information can be found in the Numpy documentation

<your_array>.flatten()

Leave a Reply