Re: Манхэттенское расстояние. Задание 2.

From Smelly Hornbill, 4 Months ago, written in Python, viewed 129 times. This paste is a reply to Манхэттенское расстояние. Задание 2. from Алексей Богачев - view diff
URL http://codebin.org/view/c5205a6c Embed
Download Paste or View Raw
  1. import numpy as np
  2. import pandas as pd
  3. from scipy.spatial import distance
  4.  
  5. avenues_df = pd.DataFrame([0, 153, 307, 524], index=['Park', 'Lexington', '3rd', '2nd'])
  6. streets_df = pd.DataFrame([0, 81, 159, 240, 324], index=['76', '75', '74', '73', '72'])
  7.  
  8. address = ['Lexington', '74']
  9. taxies = [
  10.     ['Park', '72'],
  11.     ['2nd', '75'],
  12.     ['3rd', '76'],
  13. ]
  14.  
  15. address_vector = np.array([avenues_df.loc[address[0]], streets_df.loc[address[1]]])
  16. taxi_distances = []
  17.  
  18. for taxi in taxies:
  19.     taxi_distances.append(distance.cityblock(address_vector,
  20.                                              np.array(avenues_df.loc[taxi[0]],
  21.                                                       streets_df.loc[taxi[1]]
  22.                                                      )
  23.                                             )
  24.                          )
  25.    
  26. index = np.array(taxi_distances).argmin()
  27. print(taxies[index])

Reply to "Re: Манхэттенское расстояние. Задание 2."

Here you can reply to the paste above