title: How to properly use sklearn cosine_similarity with a dictionary
body: <p>I have a csv file that contains an id, and then 4000 extra columns of floating point numbers.
  so a row looks like:</p>
  
  <pre><code>12323,3.8,3.1,4.2,.....
  </code></pre>
  
  <p>I am trying to compare a single row with the others rows to fid which rows re most similar  using a cosine distance metric. Currently, I compare each row from a numpy array individually to a single item. I want to be able to compare all the items at once instead of comparing one item at a time.  The problem is I use a dictionary because I use the key to reference each object. As you can see in the code below, dict stores the id as as the key and then the value is the an array of the floating point numbers.</p>
  
  <pre><code>#item is the single item
  dict= {}
  scores = {}
  with open(file, 'rb') as csvfile:
    reader = csv.reader(csvfile, delimiter=',', quotechar='|')
    for row in reader:
      dict[row[1]] = np.loadtxt(row[2:],delimiter=',')
  
  for k,v in dict.iteritems():
    score = cosine_similarity(item,v)
    scores[k] = score
  sorted_scores = sorted(scores.items(), key=operator.itemgetter(1))
  print(sorted_scores[-args.k:])
  </code></pre>
  
  <p>how can I  get the same result but without using the for loop to individually score each row. From reading the distance metrics I should be able to pass a whole array of rows into cosine_similarity.</p>