Reputation: 61
I am trying to create a function that computes the following formula:
The function takes two dictionaries as inputs and must return a positive real number.
Please help figure out how to use sigma in python and carry out this equation. Thank you in advance for your help/feedback!
Upvotes: 0
Views: 168
Reputation: 190
Here is a function that you can use. Based on what you have said in the comments, the dictionaries must have the same keys, and based on that assumption this function should do the job:
def calculate_distance(obs_dict, exp_dict):
distance = 0
for key in obs_dict.keys():
distance += (obs_dict[key] - exp_dict[key]) ** 2 / exp_dict[key]
return distance
Upvotes: 1