Add indexes_to_cities function
This commit is contained in:
parent
309cd59e7d
commit
4455a4e6f4
17
common.py
17
common.py
@ -3,6 +3,7 @@ from typing import Dict, List, Tuple
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
from numpy._typing import NDArray
|
||||
|
||||
# Data given by the assignment
|
||||
city_coords: Dict = {
|
||||
@ -41,7 +42,7 @@ def plot_plan(city_order: List[str]) -> None:
|
||||
Args:
|
||||
city_order (List[str]): A list of cities in the order to be plotted.
|
||||
|
||||
Returns:
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
|
||||
@ -72,6 +73,20 @@ def plot_plan(city_order: List[str]) -> None:
|
||||
plt.show()
|
||||
|
||||
|
||||
def index_to_city(indexes: npt.NDArray, cities: npt.NDArray) -> npt.NDArray:
|
||||
"""Create an array of cities from indeces in a specific order.
|
||||
|
||||
Args:
|
||||
indexes (npt.NDArray): An array of city indexes.
|
||||
cities (npt.NDArray): An array of cities.
|
||||
|
||||
Returns:
|
||||
npt.NDArray An array of cities in the same order as given in indexes.
|
||||
"""
|
||||
|
||||
return np.array([cities[i] for i in indexes])
|
||||
|
||||
|
||||
def read_data(file_path: str) -> Tuple[npt.NDArray, npt.NDArray]:
|
||||
"""Read the city data from a file given and return 2 arrays.
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user