Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading