So we can do this in with numpy arrays:
IN: a = np.array([1,2,3]) b = np.array([[1,2,3], [1,2,4], [1,2,5]]) a+b OUT: array([[2, 4, 6], [2, 4, 7], [2, 4, 8]])
I have this function, where di and dj are lists or arrays of the same lenght and KL is scipy.stats.entropy
def dis(di,dj): di = np.array(di) dj = np.array(dj) m = 0.5 * (di+dj) kl1 = KL(di,m) kl2 = KL(dj,m) return 0.5*(kl1+kl2)
I was wondering if there was a way to apply the function as with a+b:
dis(a,b)
So instead of doing:
for x in b:
dis(a,x)
I am getting this error when trying to run:
dis(a,b)
UPDATE After resolving the error thanks to hpaulj suggestion I get the following result: Result 2
The problem with the result is that KL should only give positive values. So I don't get quiet well what does: dis(a,b) is actually doing.