title: Concatenating dictionaries of numpy arrays (avoiding manual loops if possible)
body: <p>I am looking for a way to concatenate the values in two python dictionaries that contain numpy arrays whilst avoiding having to manually loop over the dictionary keys. For example:</p>
  
  <pre><code>import numpy as np
  
  # Create first dictionary
  n = 5
  s = np.random.randint(1,101,n)
  r = np.random.rand(n)
  d = {"r":r,"s":s}
  print "d = ",d
  
  # Create second dictionary
  n = 2
  s = np.random.randint(1,101,n)
  r = np.random.rand(n)
  t = np.array(["a","b"])
  d2 = {"r":r,"s":s,"t":t}
  print "d2 = ",d2
  
  # Some operation to combine the two dictionaries...
  d = SomeOperation(d,d2)
  
  # Updated dictionary
  print "d3 = ",d
  </code></pre>
  
  <p>to give the output</p>
  
  <pre><code>&gt;&gt; d =  {'s': array([75, 25, 88, 54, 82]), 'r': array([ 0.1021227 ,  0.99454874, 0.38680718,  0.98720877,  0.8662894 ])}
  &gt;&gt; d2 =  {'s': array([78, 92]), 'r': array([ 0.27610587,  0.57037473]), 't': array(['a', 'b'], dtype='|S1')}
  &gt;&gt; d3 =  {'s': array([75, 25, 88, 54, 82, 78, 92]), 'r': array([ 0.1021227 ,  0.99454874, 0.38680718,  0.98720877,  0.8662894, 0.27610587,  0.57037473]), 't': array(['a', 'b'], dtype='|S1')}
  </code></pre>
  
  <p>i.e. so that if the key already exists, the numpy array stored under that key is appended to.</p>
  
  <p>Does anybody know the best way to do this, whilst minimising the use of slow, manual <code>for</code> loops? (I would like to avoid loops because the dictionaries I would like to combine could have hundreds of keys).</p>
  
  <p>Thanks!</p>