Add indexes_to_cities function

This commit is contained in:
Cory Balaton 2024-10-01 19:05:58 +02:00
parent 309cd59e7d
commit 4455a4e6f4
Signed by: coryab
GPG Key ID: F7562F0EC4E4A61B

View File

@ -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 = {
@ -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.