title: Numpy create an index of values in an array and replace values by others
body: <p>I have two sets of values <code>RGB</code> and <code>XYZ</code> in <code>np.arrays</code> that have the same length. The values in <code>RGB</code> and <code>XYZ</code> correspond to the same values in two different color spaces, <strong>the order of their appearance</strong> in the vectors is the same.</p>
  
  <p>I have another array <code>RGB_picture</code> that contains values similar to the ones listed in <code>RGB</code>.</p>
  
  <p>I want to find a way to replace the <code>RGB</code> values in <code>RGB_picture</code> by the corresponding <code>XYZ</code> values in a new array <code>XYZ_picture</code>.</p>
  
  <p>example:</p>
  
  <pre><code>RGB = np.array([[0,0,0], [0,0,1], [0,1,0], [0,1,1], [1,0,0], [1,0,1], [1,1,1]])
  
  XYZ = np.array([[0.237,0.32,0.8642], [0.43234,0.34,1], [0.2432,.31,0.324], [0.3242,1.324,1.234], [1.32,0.4,0.23], [1.432,0.32423,1.342], [1.234,1.324,1.324324]])
  
  #6 pixels image
  RGB_image = np.array([[[0,0,1],[0,0,1],[0,0,1],
                         [0,1,1],[1,0,0],[1,0,1]]])
  
  """I want to return this"""
  
  &gt;print XYZ_image 
  
  &gt;[[0.43234,0.34,1],[0.43234,0.34,1],[0.43234,0.34,1]],
  
  &gt;[0.3242,1.324,1.234], [1.32,0.4,0.23], [1.432,0.32423,1.342]]
  </code></pre>
  
  <p>I tried to do it with numpy but couldn't find how, would you help a bit?</p>
  
  <p>Here's what I have but it is no numpy solution, so it is very slow:</p>
  
  <pre><code>XYZ_image = np.zeros_like(RGB_image)
  
  w, h = RGB_image.shape
  
  for i in xrange(w):
      for j in xrange(h):
          pixel = RGB_image[i,j]
  
          for k in xrange(len(RGB)):
  
              rgb = RGB[k]
  
              if rgb == pixel:
  
                  XYZ_image[i,j] = XYZ[k]
                  break
  </code></pre>