title: How to recode integers to other values in python?
body: <p>I was surprised this question has not been asked yet. Given an array of integers</p>
  
  <pre><code>x = np.random.randint(1,4,10)
  
  &gt; array([3, 2, 1, 2, 1, 1, 3, 3, 2, 1])
  </code></pre>
  
  <p>How can I (easily) change all values according to some systematic rule, such as </p>
  
  <pre><code>x[x==1] = 5
  x[x==2] = 6
  x[x==3] = 7
  
  &gt; array([6, 5, 6, 7, 5, 5, 6, 5, 7, 6])
  </code></pre>
  
  <p>The rule may be more complex than this, e.g. recode <code>1=2</code> and <code>2=1</code> so that the order plays a role.</p>