title: Replace elements of a multidimensional numpy array according to a rule
body: <p>Let's say we have a numpy array:</p>
  
  <pre><code>import numpy as np
  arr = np.array([[ 5,  9],[14, 23],[26,  4],[ 5, 26]])
  </code></pre>
  
  <p>I want to replace each element with its number of occurrences,</p>
  
  <pre><code> unique0, counts0= np.unique(arr.flatten(), return_counts=True)
   print (unique0, counts0)
  </code></pre>
  
  <blockquote>
    <p>(array([ 4,  5,  9, 14, 23, 26]), array([1, 2, 1, 1, 1, 2]))</p>
  </blockquote>
  
  <p>so 4 should be replaced by 1, 5 by 2, etc to get:</p>
  
  <blockquote>
    <p>[[ 2,  1],[1, 1],[2,  1],[ 2, 2]]</p>
  </blockquote>
  
  <p>Is there any way to achieve this in numpy?</p>