Add indexes_to_cities function
This commit is contained in:
parent
309cd59e7d
commit
4455a4e6f4
15
common.py
15
common.py
@ -3,6 +3,7 @@ from typing import Dict, List, Tuple
|
|||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import numpy.typing as npt
|
import numpy.typing as npt
|
||||||
|
from numpy._typing import NDArray
|
||||||
|
|
||||||
# Data given by the assignment
|
# Data given by the assignment
|
||||||
city_coords: Dict = {
|
city_coords: Dict = {
|
||||||
@ -72,6 +73,20 @@ def plot_plan(city_order: List[str]) -> None:
|
|||||||
plt.show()
|
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]:
|
def read_data(file_path: str) -> Tuple[npt.NDArray, npt.NDArray]:
|
||||||
"""Read the city data from a file given and return 2 arrays.
|
"""Read the city data from a file given and return 2 arrays.
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user