从现有距离列表创建距离矩阵

I have a list of distance increase between every two adjacent stations in a railroad in the right order starting from 0 in the first station of the route and growing while going through the stations until the end. What I need to do is to create a matrix for the distances between every two stations. I know how to make a matrix itself but I do not know how to implement the sums of the distances for some of the combinations of stations such as how to count distance from SF (1st station) to Bayshore (3rd station) if I have distances from 1st to 2nd and from 2nd to 3rd (of course, summarize them, but how to use this sum in a large scale of all matrix).

+-------------------------+-------------------------+---------------+
|    Departure Station    |     Arrival Station     | distance in m |
+-------------------------+-------------------------+---------------+
| San Francisco           | 22nd Street             |   2521.949349 |
| 22nd Street             | Bayshore                |   8397.847949 |
| Bayshore                | South San Francisco     |   15088.00923 |
| South San Francisco     | San Bruno               |   18052.86281 |
| San Bruno               | Millbrae Transit Center |   22207.65488 |
| Millbrae Transit Center | Broadway                |   24756.82685 |
| Broadway                | Burlingame              |   26519.48003 |
| Burlingame              | San Mateo               |   28827.32764 |
| San Mateo               | Hayward Park            |   30976.31977 |
| Hayward Park            | Hillsdale               |    33574.2521 |
| Hillsdale               | Belmont                 |    35666.4021 |
| Belmont                 | San Carlos              |    37656.6417 |
| San Carlos              | Redwood City            |   41149.25982 |
| Redwood City            | Atherton                |   44996.90435 |
| Atherton                | Menlo Park              |   46749.82653 |
| Menlo Park              | Palo Alto               |   48761.20885 |
| Palo Alto               | Stanford                |   50343.87275 |
| Stanford                | California Ave.         |   51309.47875 |
| California Ave.         | San Antonio             |   55249.16386 |
| San Antonio             | Mountain View           |   58357.57814 |
| Mountain View           | Sunnyvale               |   62670.09556 |
| Sunnyvale               | Lawrence                |   65860.03933 |
| Lawrence                | Santa Clara             |   71749.71946 |
| Santa Clara             | College Park            |   74002.15007 |
| College Park            | San Jose Diridon        |   75875.00727 |
| San Jose Diridon        | Tamien                  |   78762.97475 |
| Tamien                  | Capitol                 |   83762.18633 |
| Capitol                 | Blossom Hill            |   89066.38875 |
| Blossom Hill            | Morgan Hill             |   108117.1541 |
| Morgan Hill             | San Martin              |   114034.7036 |
| San Martin              | Gilroy                  |   124096.2983 |
+-------------------------+-------------------------+---------------+

请帮助!谢谢。

评论