title: Calculate euclidean distance from dicts (sklearn)
body: <p>I have two <code>dictionaries</code> already calculated in my code, which look like this:</p>
  
  <pre><code>X = {'a': 10, 'b': 3, 'c': 5, ...}
  Y = {'a': 8, 'c': 3, 'e': 8, ...}
  </code></pre>
  
  <p>Actually they contain words from wiki texts, but this should serve to show what I mean. They don't necessarily contain the same keys.</p>
  
  <p>Initially I wanted to use <code>sklearn</code>'s pairwise metric like this:</p>
  
  <pre><code>from sklearn.metrics.pairwise import pairwise_distances
  
  obama = wiki[wiki['name'] == 'Barack Obama']['tf_idf'][0]
  biden = wiki[wiki['name'] == 'Joe Biden']['tf_idf'][0]
  
  obama_biden_distance = pairwise_distances(obama, biden, metric='euclidean', n_jobs=2)[0][0]
  </code></pre>
  
  <p>However, this gives an error:</p>
  
  <pre><code>--------------------------------------------------------------------------
  AttributeError                            Traceback (most recent call last)
  &lt;ipython-input-124-7ff03bd40683&gt; in &lt;module&gt;()
        6 biden = wiki[wiki['name'] == 'Joe Biden']['tf_idf'][0]
        7 
  ----&gt; 8 obama_biden_distance = pairwise_distances(obama, biden, metric='euclidean', n_jobs=2)[0][0]
  
  /home/xiaolong/development/anaconda3/envs/coursera_ml_clustering_and_retrieval/lib/python3.4/site-packages/sklearn/metrics/pairwise.py in pairwise_distances(X, Y, metric, n_jobs, **kwds)
     1205         func = partial(distance.cdist, metric=metric, **kwds)
     1206 
  -&gt; 1207     return _parallel_pairwise(X, Y, func, n_jobs, **kwds)
     1208 
     1209 
  
  /home/xiaolong/development/anaconda3/envs/coursera_ml_clustering_and_retrieval/lib/python3.4/site-packages/sklearn/metrics/pairwise.py in _parallel_pairwise(X, Y, func, n_jobs, **kwds)
     1058     ret = Parallel(n_jobs=n_jobs, verbose=0)(
     1059         fd(X, Y[s], **kwds)
  -&gt; 1060         for s in gen_even_slices(Y.shape[0], n_jobs))
     1061 
     1062     return np.hstack(ret)
  
  AttributeError: 'dict' object has no attribute 'shape'
  </code></pre>
  
  <p>To me this reads like something is trying to access the <code>shape</code> attribute, which a <code>dict</code> doesn't have. I guess it needs <code>numpy</code> arrays. How can I transform the dictionaries, so that the <code>sklearn</code> function will compute the correct distance, assuming <code>0</code> values, if a dictionary does not have a certain key, which the other dictionary has?</p>