hello. I am quite new in python so i have a question. I have a csv file in which i have names of 30 cities and their coordinates(lat and long). i want to generate a distance matrix for these cities. How can i do this ?
toritza 0 Junior Poster in Training
Recommended Answers
Jump to PostYou can generate list of list of distances to every other city by list comprehension or for loop using Pythagoras triangle formula, if exactness is not needed, else you need to find about
Jump to Postlen() i understood. " ".join(cities) --this is something new for me.
So iTried this : >>> cities = [ entry[1] for entry in elements ] >>> " ".join(cities) 'Acatari Acis Adamclisi'
Then as matrix is a list of lists i thought i could do this
dist = …
Jump to PostIt worked for the distances
elements=[('Acatari', 'Acatari', 0.0), ('Acatari', 'Acis', 183.198428622), ('Acatari', 'Adamclisi', 372.526412318)] def ntostr(number, precision=3): return "{0:.{1}f}".format(number, precision) sdist = [ ntostr(entry[2], 3) for entry in elements ] print " ".join(sdist)
giving the wanted result
0.000 183.198 372.526
but when i try to add this code …
Jump to PostI changed by mistake number with result as the change was intended in the line after that. I had a file where i was working with elements and and one with result.
now in what concerns columns i am not very familiar with them. What should i do to insert …
Jump to PostBut i use result = useful_entries(cities) as the entries generated by the previos function.
And if i were not usong the curreent function could i still be usingif result[0] == cities[1]: #with entries instead of result res.append(entry[2])
Or i do not really understand?
I don't understand. If you …
All 85 Replies
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
toritza 0 Junior Poster in Training
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
toritza 0 Junior Poster in Training
toritza 0 Junior Poster in Training
zizuno 0 Junior Poster in Training
toritza 0 Junior Poster in Training
Gribouillis 1,391 Programming Explorer Team Colleague
toritza 0 Junior Poster in Training
Gribouillis 1,391 Programming Explorer Team Colleague
toritza 0 Junior Poster in Training
Gribouillis 1,391 Programming Explorer Team Colleague
toritza 0 Junior Poster in Training
Gribouillis 1,391 Programming Explorer Team Colleague
toritza 0 Junior Poster in Training
Gribouillis 1,391 Programming Explorer Team Colleague
toritza 0 Junior Poster in Training
Gribouillis 1,391 Programming Explorer Team Colleague
toritza 0 Junior Poster in Training
Gribouillis 1,391 Programming Explorer Team Colleague
toritza 0 Junior Poster in Training
Gribouillis 1,391 Programming Explorer Team Colleague
toritza 0 Junior Poster in Training
Gribouillis 1,391 Programming Explorer Team Colleague
toritza 0 Junior Poster in Training
Gribouillis 1,391 Programming Explorer Team Colleague
toritza 0 Junior Poster in Training
Gribouillis 1,391 Programming Explorer Team Colleague
toritza 0 Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.