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]]
>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:])]