i'm trying to write a function called compute.
import math
def compute(index):
res=0
x=0
res = sum(val[-1] * val[-1] for key,val in index.items())
x = math.sqrt(res)
return x
My output:
>>compute({'a': [0, 3], 'b': [0, 4]})
5.0
In the sample index above, document 0 has two terms 'a' (with tf-idf weight 3) and 'b' (with tf-idf weight 4). It's length is therefore 5 = sqrt(9 + 16).
Now how do i access list of lists elements within a dictionary ??
example, compute({'a': [[0, 3]], 'b': [[0, 4]]})
So that my desired output looks like this,
Desired output:
>>length = compute(({'a': [[0, 3]], 'b': [[0, 4]]})
>>length[0]
5.0
so that the computation should happen for each list separately. As in, for example
>>length = compute(({'a': [[0, 3],[1,3]], 'b': [[0, 4],[1,2]]})
>>length[1]
3.6
Can anyone suggest help to modify my function ???