Python Forum
dot product of a list by a list in a dictionary stored as a value - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: dot product of a list by a list in a dictionary stored as a value (/thread-25285.html)



dot product of a list by a list in a dictionary stored as a value - Fraher123 - Mar-25-2020

def similiar():
n=input()
for name,rating in ratingsdict.items():
if name == n:
return(rating)

for key in ratingsdict():
print(sum(ratingsdict[key]*rating for ratingsdict[key], rating in zip(ratingsdict[key], ratings)))

similiar()


I have created a dictionary already and I am trying to do the dot product on all of the lists within the dictionary with another list that is in rating but I am unable to achieve this.


RE: dot product of a list by a list in a dictionary stored as a value - deanhystad - Mar-25-2020

Where is ratingsdict? Can similar() see the ratingsdict dictionary? Where is ratings? Can similar() see ratings? You need to surround your source with python tags to preserve the formatting. I don't know what code is part of similar() and what is not. If I don't know what code is in similar() I don't know if you are going to have a variable scope problem or not.

When I run this code I get an error that name ratingsdict is not defined. Is that the error you see? Do you see an error or do you just not get the results you expect? You need to provide more information about your problem and about what it is you are trying to do.