Ask Your Question
1

how to find distance matrix in order?

asked 3 years ago

Vinayak gupta gravatar image

updated 3 years ago

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.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 3 years ago

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
Preview: (hide)
link

Comments

thank you.

Vinayak gupta gravatar imageVinayak gupta ( 3 years ago )

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: 3 years ago

Seen: 254 times

Last updated: Nov 30 '21