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 split an array homogene in half of size by taking the triagle?

i have this array and i want to split it in the half how i can do it?

a = [[0., 15., 19., 18., 17.],
     [15., 0., 14., 12., 23.],
     [19., 14.,  0., 14., 21.],
     [18., 12., 14., 0., 14.],
     [17., 23., 21., 14.,  0.]]

how i can get this half size of this array:

[[0.],
    [15.,0],
    [19., 14.,0],
    [18., 12., 14.,0],
    [17., 23., 21., 14.,0]]

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 do something like this :

half = [row[:i+1] for i, row in enumerate(a)]

If you do not want the diagonal, you can add [1:] :

half = [row[:i+1] for i, row in enumerate(a[1:])]
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