title: Python: Cosine Similarity between different size of NumPy arrays
body: <p>I have a dictionary that has keys representing item_ids. Values of the dictionary is numpy array as follows: Prior to converting to dictionary data was in following format.</p>
  
  <pre><code>item_id tag_id_1, tag_id_2....  tag_id_n
  1, 2323, 23423, 
  
  {1: array([1, 3, 4, 1, 4]), 2: array([ 23. ,  35. ,  32.6,   1. ,   1. ,   1. ,   3. ,   5. ,   6. ]), 3: array([23, 35, 32]), 4: array([1, 5, 6])}
  </code></pre>
  
  <p>My goal is to find cosine similarity between keys and generate a dictionary as follows:</p>
  
  <pre><code>{1:[1,3], 2:[1,4]}
  </code></pre>
  
  <p>I was trying to use <code>TfidfVectorizer()</code> class of the <code>scikit learn</code> but the fit_transform method required to have list which means I have to take all my numpy array elements and append to a list. Once I do that its hard to track back the key of the each numpy array. </p>
  
  <p>This is the route I was going to go: </p>
  
  <pre><code>matrix = tfidf_vectorizer.fit_transform(list_of_values)
  for feature_idx in xrange(len(list_of_values)):
      cosine_similarities = linear_kernel(tfidf_matrix[0:feature_idx], matrix)
  </code></pre>
  
  <p>Using below dictionary How can I calculate cosine similarity between keys?</p>
  
  <pre><code>{1: array([1, 3, 4, 1, 4]), 2: array([ 23. ,  35. ,  32.6,   1. ,   1. ,   1. ,   3. ,   5. ,   6. ]), 3: array([23, 35, 32]), 4: array([1, 5, 6])}
  </code></pre>