beginner_coder
beginner_coder

Reputation: 61

Function with dictionary inputs and using sigma in python

I am trying to create a function that computes the following formula:

enter image description here

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

Answers (1)

Reza Dodge
Reza Dodge

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

Related Questions