Ask Your Question
1

how to find distance matrix in order?

asked 2021-11-30 04:28:59 +0100

Vinayak gupta gravatar image

updated 2021-11-30 18:16:32 +0100

slelievre gravatar image

After defining:

helm111 = {'1': ['2', '3', '4'], '2': ['5', '4'], '3': ['6', '4'], '4': ['7']}
Graph(helm111)
D99 = Graph(helm111).distance_matrix()

i need to find distance matrix in order of vertices 1,2,3,5,6,8,4,7,9,11,10.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-11-30 09:16:47 +0100

As documented (see D99.distance_matrix? to get the documentation), you can specify the order of the vertices in the columns. Note that some vertices are missing in the order you ask for...

sage: helm111 = {'1':['2','3','4'],'2':['5','4'],'3':['6','4'],'4':['7']}
sage: D99 = Graph(helm111)
sage: D99.distance_matrix(vertices=['1','2','3','5','6','4','7'])
[0 1 1 2 2 1 2]
[1 0 2 1 3 1 2]
[1 2 0 3 1 1 2]
[2 1 3 0 4 2 3]
[2 3 1 4 0 2 3]
[1 1 1 2 2 0 1]
[2 2 2 3 3 1 0]
sage: D99.distance('1', '7')
2
sage: D99.distance('6', '2')
3
edit flag offensive delete link more

Comments

thank you.

Vinayak gupta gravatar imageVinayak gupta ( 2022-01-03 15:05:34 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-11-30 04:28:59 +0100

Seen: 236 times

Last updated: Nov 30 '21