Question: Why is this code returning as invalid syntax on Phyton 3.6.0? Code is supposed to implement a function with Python protoype (def bhatt_dist(D1, D2, n)
Why is this code returning as invalid syntax on Phyton 3.6.0?
Code is supposed to implement a function with Python protoype (def bhatt_dist(D1, D2, n) which computes the Bhattacharyya distance between D1 and D2.
D1 = [1/2, 1/2] and D2 = [59/100, 41/100] should be used as a test case (the correct output is given above).
The math library needs to be included which is: import math in Python.
The main function that is needed from math is the natural logarithm, which is denoted as math.log .
import math def bhatt_dist(D1, D2, n): BCSum = 0 for i in range(n): BCSum += math.sqrt(D1[i] * D2[i]) DBValue = - math.log(BCSum) return DBValue D1 = [1 , 2, 1, 2] D2 = [ 59 ,100, 41, 100] print bhatt_dist(D1, D2, 2)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
