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 PostYou mean that it sould be somethong like this?
def entry_to_line(entry) entry = ', '.join(map(str,entry)) return entry print entry_to_line()
Or i got it again confused?
It's almost correct. There is a missing newline if we want to adhere to the specifications, also it's better to chose a new name …
Jump to PostYou are doing some some thing that are not good at all.
assert lin == "Acatari, Aiud, 72.639\n"
Read about the use of assert and that you use == make it strange¨.
assert <<expression, error_message>> is a form of error checking.
It raises an exception if the expression evaluates to false and …
Jump to PostYou are right i have not paid enough attention to the code.
But retourning to my generated matrix, as Gribouillis suggested i had to change the format of my Te.csv file in order to write the way i wanted the matrixname1 name2 name3 name1 0 distA distB …
Jump to PostI read the tutorial and i tried this
result = read_3_entries() result.insert(0," ")
printed
[' ', ('Acatari', 'Acatari', 0.0), ('Acatari', 'Acis', 183.198428622), ('Acatari', 'Adamclisi', 372.526412318)]
but it gave
at the next lines of code this error
sdist = [ ntostr(entry[2], 3) for entry in result ]
IndexError: string …
All 85 Replies
TrustyTony
888
pyMod
Team Colleague
Featured Poster
toritza
0
Junior Poster in Training
TrustyTony
888
pyMod
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.