I have a 2 dim numpy array with distances from one startpoint to each endpoint and i want to sort the distances, but to do that i have to give the distances an index so i don't loose the refernce to the endpoint.
How can i add the index? Best without loops
I have already expanded the array by 1 dim using numpy.expand_dims but i don't know how to append the indices.
So my current approach is:
indexArray = [1,2,3]
distances = np.array([[0.3, 0.5, 0.2], [0.7, 0.1, 0.5], [0.2, 0.3, 0.8]])
distances = np.expand_dims(distances, axis=2)
now distances looks like:
[[[0.3], [0.5], [0.2]],
[[0.7], [0.1], [0.5]],
[[0.2], [0.3], [0.8]]]
and now I want to append the indexArray so the distance array looks like:
[[[1, 0.3], [2, 0.5], [3, 0.2]],
[[1, 0.7], [2, 0.1], [3, 0.5]],
[[1, 0.2], [2, 0.3], [3, 0.8]]]