Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

cosine similiarity OF A VECTOR WITH OTHER VECTORS IN A MATRIX

a = np.random.randint(0,10,(5,5))
print(a)
array([[5, 2, 0, 4, 1],
       [4, 2, 8, 2, 4],
       [9, 7, 4, 9, 7],
       [4, 6, 0, 1, 3],
       [1, 1, 2, 5, 0]])

from sklearn.metrics.pairwise import cosine_similarity
cosine_similarity(a[None,:,-1] , a.T[:-1])
# array([[0.94022805, 0.91705665, 0.75592895, 0.79921221, 1.        ]])
Comment

PREVIOUS NEXT
Code Example
Python :: create a distance matrix from a coordinate matrix in python 
Python :: pyspark pivot max aggregation 
Python :: check entries smaller 0 after groupby 
Python :: python default summary statistics for all columns 
Python :: print hello in python 
Python :: dont limit padnas jupyter 
Python :: remove punctuation in dataframe column 
Python :: keep calm and carry on memes 
Python :: how to install python on visual studio code 
Python :: function to sort a list of points based on their x and y-coordinates 
Python :: python3 create dictionary 
Python :: python convert py to exe 
Python :: python open application windows 
Python :: how to change directory in python 
Python :: how to sort a dictionary in python without sort function 
Python :: python merge sort 
Python :: age calculator python 
Python :: youtube download in python 
Python :: check how many letters in a string python 
Python :: python remove last 4 characters from string 
Python :: for range python 
Python :: rename folder python 
Python :: python ValueError: zero-size array to reduction operation maximum which has no identity 
Python :: python permission denied 
Python :: Python - How To Convert Bytearray to String 
Python :: how to replace zero value in python dataframe 
Python :: django or flask 
Python :: python class variables 
Python :: iterator in python 
Python :: tkinter filedialog 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =