How to fix inefficient nested dictionary with haversine distances between locationsHow do you sort a dictionary by value?Calculate distance between two latitude-longitude points? (Haversine formula)How to merge two dictionaries in a single expression?How do I sort a list of dictionaries by a value of the dictionary?How do I sort a dictionary by value?How to copy a dictionary and only edit the copyHow can I sort a dictionary by key?How to remove a key from a Python dictionary?Fast Haversine Approximation (Python/Pandas)Error while getting the distance between two co-ordinates

Could you fall off a planet if it was being accelerated by engines?

Why can't you move another user's directory when you can move their file?

Have any large aeroplanes been landed — safely and without damage — in locations that they could not be flown away from?

Calculus, Water Poured into a Cone: Why is Derivative Non-linear?

Journal standards vs. personal standards

List Manipulation : a,b,c,d,e,f,g,h into a,b,c,d,e,f,g,h

Single level file directory

What do you call a notepad used to keep a record?

How can a valley surrounded by mountains be fertile and rainy?

Why was p[:] designed to work differently in these two situations?

Robots in a spaceship

Using If statements to conditionally populate a field in Field Calculator

Losing queen and then winning the game

How to create new column in dataframe from existing column using conditions

Can a successful book series let the bad guy win?

Is there a way to convert blue ice back into packed ice?

How did they film the Invisible Man being invisible, in 1933?

Two palindromes are not enough

When was this photo of Mission Dolores *actually* taken?

Simple logic puzzle

Should 私の be omitted?

If two black hole event horizons overlap (touch) can they ever separate again?

How to securely dispose of a smartphone?

Why isn't UDP with reliability (implemented at Application layer) a substitute of TCP?



How to fix inefficient nested dictionary with haversine distances between locations


How do you sort a dictionary by value?Calculate distance between two latitude-longitude points? (Haversine formula)How to merge two dictionaries in a single expression?How do I sort a list of dictionaries by a value of the dictionary?How do I sort a dictionary by value?How to copy a dictionary and only edit the copyHow can I sort a dictionary by key?How to remove a key from a Python dictionary?Fast Haversine Approximation (Python/Pandas)Error while getting the distance between two co-ordinates






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have made a nested dictionary which contains the distances between locations and all other distances.



for example:



city1 :city1 : 0, city2: 2, city3: 3, city4: 4
city2 : city1: 2, city2: 0, city3: 1, city4:2
city3 : …


My code does deliver this, although it works extremely inefficiently.
I am wondering why and how to improve it, since when I try changing it, the code gives an error saying that tuple indices can not be strings or lists or tuples.



So the code now does deliver, however it takes way too long.



I am looking for a way to improve it & to understand why this works but takes this long.



The data is a dataframe containing city numbers and lattitude and longitude coordinates.



 def distances_dict(data):
all_distances =
for row in data.iterrows():
all_distances[row[1]['City Nr.']] =
for row2 in data.iterrows():
all_distances[row[1]['City Nr.']][row2[1]['City Nr.']]=
haversine(row[1][['Lat','Long']],row2[1][['Lat','Long']])
return all_distances









share|improve this question




























    0















    I have made a nested dictionary which contains the distances between locations and all other distances.



    for example:



    city1 :city1 : 0, city2: 2, city3: 3, city4: 4
    city2 : city1: 2, city2: 0, city3: 1, city4:2
    city3 : …


    My code does deliver this, although it works extremely inefficiently.
    I am wondering why and how to improve it, since when I try changing it, the code gives an error saying that tuple indices can not be strings or lists or tuples.



    So the code now does deliver, however it takes way too long.



    I am looking for a way to improve it & to understand why this works but takes this long.



    The data is a dataframe containing city numbers and lattitude and longitude coordinates.



     def distances_dict(data):
    all_distances =
    for row in data.iterrows():
    all_distances[row[1]['City Nr.']] =
    for row2 in data.iterrows():
    all_distances[row[1]['City Nr.']][row2[1]['City Nr.']]=
    haversine(row[1][['Lat','Long']],row2[1][['Lat','Long']])
    return all_distances









    share|improve this question
























      0












      0








      0








      I have made a nested dictionary which contains the distances between locations and all other distances.



      for example:



      city1 :city1 : 0, city2: 2, city3: 3, city4: 4
      city2 : city1: 2, city2: 0, city3: 1, city4:2
      city3 : …


      My code does deliver this, although it works extremely inefficiently.
      I am wondering why and how to improve it, since when I try changing it, the code gives an error saying that tuple indices can not be strings or lists or tuples.



      So the code now does deliver, however it takes way too long.



      I am looking for a way to improve it & to understand why this works but takes this long.



      The data is a dataframe containing city numbers and lattitude and longitude coordinates.



       def distances_dict(data):
      all_distances =
      for row in data.iterrows():
      all_distances[row[1]['City Nr.']] =
      for row2 in data.iterrows():
      all_distances[row[1]['City Nr.']][row2[1]['City Nr.']]=
      haversine(row[1][['Lat','Long']],row2[1][['Lat','Long']])
      return all_distances









      share|improve this question














      I have made a nested dictionary which contains the distances between locations and all other distances.



      for example:



      city1 :city1 : 0, city2: 2, city3: 3, city4: 4
      city2 : city1: 2, city2: 0, city3: 1, city4:2
      city3 : …


      My code does deliver this, although it works extremely inefficiently.
      I am wondering why and how to improve it, since when I try changing it, the code gives an error saying that tuple indices can not be strings or lists or tuples.



      So the code now does deliver, however it takes way too long.



      I am looking for a way to improve it & to understand why this works but takes this long.



      The data is a dataframe containing city numbers and lattitude and longitude coordinates.



       def distances_dict(data):
      all_distances =
      for row in data.iterrows():
      all_distances[row[1]['City Nr.']] =
      for row2 in data.iterrows():
      all_distances[row[1]['City Nr.']][row2[1]['City Nr.']]=
      haversine(row[1][['Lat','Long']],row2[1][['Lat','Long']])
      return all_distances






      dictionary nested haversine coding-efficiency






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 25 at 14:47









      ValérieValérie

      11 bronze badge




      11 bronze badge






















          0






          active

          oldest

          votes










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55340472%2fhow-to-fix-inefficient-nested-dictionary-with-haversine-distances-between-locati%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes




          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55340472%2fhow-to-fix-inefficient-nested-dictionary-with-haversine-distances-between-locati%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript