title: How to replace a list of values in a numpy array?
body: <p>I have an unsorted array of numbers. </p>
  
  <p>I need to replace certain numbers (given in a list) with specific alternatives (also given in a corresponding list) </p>
  
  <p>I wrote the following code (which seems to works): </p>
  
  <pre><code>import numpy as np
  
  numbers = np.arange(0,40)
  np.random.shuffle(numbers)
  problem_numbers = [33, 23, 15]  # table, night_stand, plant
  alternative_numbers = [12, 14, 26]  # desk, dresser, flower_pot
  
  for i in range(len(problem_numbers)):
      idx = numbers == problem_numbers[i]
      numbers[idx] = alternative_numbers[i]
  </code></pre>
  
  <p>However, this seems highly inefficient (this needs to be done several millions of times for much larger arrays).</p>
  
  <p>I found <a href="https://stackoverflow.com/questions/12122639/find-indices-of-a-list-of-values-in-a-numpy-array">this</a> question which answers a similar problem however in my case the numbers are not sorted and they need to maintain their original location. </p>
  
  <p>Note: <code>numbers</code> may contain multiple or no occurrences of elements in <code>problem_numbers</code></p>