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 turn this Matrix into a list of integers?

I am trying to extract a list of integers from a input that looks like this:

[[matrix([[0.57863575]])], [matrix([[0.57170157]])], [matrix([[0.44320711]])], [matrix([[0.37195535]])]]

I am trying to get an output like so:

[0.57863575,0.57170157,0.44320711,0.37195535]

What are my options?

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 :

You can use a loop comprehension:

from numpy import matrix
l = [[matrix([[0.57863575]])], [matrix([[0.57170157]])], [matrix([[0.44320711]])], [matrix([[0.37195535]])]]

[e[0].flat[0] for e in l]

output: [0.57863575, 0.57170157, 0.44320711, 0.37195535]

The real question is, how did you get this format in the first place? It might be better to fix it there.

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