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

listing all the values inside a matrix into a 1 whole list

How can I put all the values of my matrix ckpot_p_shell_matrix into just 1 whole list? I want the values in a list so I can do a histogram plot of the values.

ckpot_p_shell_matrix is a numpy.ndarray 2D matrix that has a shape (28, 108) containing values between 0 ~ 10.

>>> type(ckpot_p_shell_matrix)
    numpy.ndarray
>>> ckpot_p_shell_matrix.shape
    (28, 108)
>>> ckpot_p_shell_matrix
    array([[0.2407545, 0.3681921, 0.5176657, ..., 2.9999998, 1.5      ,
        2.9316723],
       [0.       , 0.       , 0.       , ..., 0.       , 0.       ,
        0.       ],
       [0.       , 0.       , 0.       , ..., 0.       , 0.       ,
        0.       ],
       ...,
       [3.5468006, 2.0326045, 2.42928  , ..., 4.5      , 5.25     ,
        3.5797157],
       [0.7088   , 1.5522   , 1.0474   , ..., 4.       , 3.       ,
        3.95444  ],
       [5.2912   , 4.4478   , 4.9526   , ..., 6.       , 7.       ,
        6.04556  ]])

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 :

Use numpy .flatten()

import numpy as np

ckpot_p_shell_matrix = np.array([[0.2407545, 0.3681921, 0.5176657, ..., 2.9999998, 1.5      ,
        2.9316723],
       [0.       , 0.       , 0.       , ..., 0.       , 0.       ,
        0.       ],
       [0.       , 0.       , 0.       , ..., 0.       , 0.       ,
        0.       ],
       ...,
       [3.5468006, 2.0326045, 2.42928  , ..., 4.5      , 5.25     ,
        3.5797157],
       [0.7088   , 1.5522   , 1.0474   , ..., 4.       , 3.       ,
        3.95444  ],
       [5.2912   , 4.4478   , 4.9526   , ..., 6.       , 7.       ,
        6.04556  ]])
print(ckpot_p_shell_matrix.flatten())

Output:

np.array([[0.2407545, 0.3681921, 0.5176657, ..., 2.9999998, 1.5      ,
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