title: Numpy broadcast through dictionary
body: <p>I've got a 2 dimensional numpy array and a dictionary which maps values found in the first column of the array to other values. For example:</p>
  
  <pre><code>&gt;&gt;&gt; x = np.array([[14, 4], [18, 2], [15, 7]])
  &gt;&gt;&gt; d = {5: 0, 7: 2, 14: 3, 15: 12, 16: 10, 18: 30}
  </code></pre>
  
  <p>All keys in <code>d</code> are not guaranteed to be in <code>x</code> though all values in the first column of <code>x</code> will be in <code>d</code>. What I want to do is replace the values in the first column of <code>x</code> with the relevant values in <code>d</code>. Something like:</p>
  
  <pre><code>&gt;&gt;&gt; x[:, 0] = d[x[:, 0]]
  </code></pre>
  
  <p>So the new array would be:</p>
  
  <pre><code>&gt;&gt;&gt; x
  array([[3, 4], [30, 2], [12, 7]])
  </code></pre>
  
  <p>Of course, this doesn't work because I'm essentially just passing the entire array into the dictionary which wants a key. The best I've come up with is using a <code>for</code> loop:</p>
  
  <pre><code>&gt;&gt;&gt; for i in range(x.shape[0]):
  ...     x[i, 1] = d[x[i, 1]]
  </code></pre>
  
  <p>Which of course is very un-numpy and probably not that efficient. My question, is there a "numpy way" of doing something like this?</p>