2022-12-20

how i can calculate the adjacent and opposite of this matrix?

i have this matrix

Matrix = [[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.]]

and i cut it to this by this code

c = [item[:index+1] for index, item in enumerate(Matrix[1:])]
c

it show that

[array([15.]),
 array([19., 14.]),
 array([18., 12., 14.]),
 array([17., 23., 21., 14.])]

and i want to calculate the adjacent and the opposite of this matrix example: 15+19+18+17 and 19+14+12+23 and 18+12+14+21 and 17 23 21 14 How i can do that

i tried this to append all data and work on it but he show nothing

arr=[]
for item,data in enumerate(c):
          for item2,data2 in enumerate(data):
                    arr.append(data2)
                    print(item,item2,data2)

print(arr)

**and i try the code below and he print the diagonal **

for item,data in enumerate(c):
          print(data[item:item+1])

and i try this and it show

for item,data in enumerate(c):
    print(item, data[0:1], data[1:2],data[2:3],data[3:4])
0 [15.] [] [] []
1 [19.] [14.] [] []
2 [18.] [12.] [14.] []
3 [17.] [23.] [21.] [14.]

so i realized that i can iterate just on columns not on row is there are a method method to solve it? This is example that i want to implement to better understand, here i want to calculate the summation of these vector this example that i want to implement



No comments:

Post a Comment