Question: Python: Modifying inner_product function to include domain, modifying Vector_angle to include intersection. import math def inner_product(L1,L2): Inner product between two vectors, where vectors are

Python: Modifying inner_product function to include domain, modifying Vector_angle to include intersection.

Python: Modifying inner_product function to include domain, modifying Vector_angle to include intersection.

import math def inner_product(L1,L2): """ Inner product between two vectors, where vectors

import math

def inner_product(L1,L2): """ Inner product between two vectors, where vectors are represented as alphabetically sorted (word,freq) pairs.

Example: inner_product([["and",3],["of",2],["the",5]], [["and",4],["in",1],["of",1],["this",2]]) = 14.0 """ sum = 0.0 i = 0 j = 0 while i

def vector_angle(L1,L2): """ The input is a list of (word,freq) pairs, sorted alphabetically. Return the angle between these two vectors. """ numerator = inner_product(L1,L2) denominator = math.sqrt(inner_product(L1,L1)*inner_product(L2,L2)) return math.acos(numerator/denominator)

- Modify inner_product to take a third argument, domain, which will be a set containing the words in both texts. Modify the code so that it only increases sum if the word is in domain. Don't forget to change the documentation string at the top. - Modify vector_angle so that it creates sets of the words in both L1 and L2, takes their intersection, and uses that intersection when calling inner_product. Again, don't forget to change the docstring at the top

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!