I have a following list of dictionaries:
clusters=[{'A': [1.0, 1.0]}, {'C': [4.0, 4.0], 'D': [4.0, 5.0], 'B': [2.0, 1.0]}]
I have written a snippet of code to access one dictionary at a time from the list:
for index, value in enumerate(clusters):
for key in value:
such that i get the following dictionaries;
{'A': [1.0, 1.0]}
{'C': [4.0, 4.0], 'D': [4.0, 5.0], 'B': [2.0, 1.0]}
What i am trying to do is find the average of ith
element of the list value in the dictionary.
For example: In the second dictionary;
x-position-average = (4.0+4.0+2.0)/3
and then assign that value to a dictionary as:
new_centroid = {"X": x-position-average,"Y": y-position-average,...}