title: revalue numpy array by order of unique appearance count
body: <p>I have 2D numpy array, I need to revalue the array by unique appearance count.</p>
  <pre><code>import numpy as np
  arr = np.array([[6, 1, 8, 5, 3],
        [2, 7, 3, 6, 9],
        [5, 3, 2, 4, 4],
        [6, 4, 6, 4, 4]])
  values, counts = np.unique(arr, return_counts=True)
  print('values',values)
  print('counts',counts)
  values [1 2 3 4 5 6 7 8 9]
  counts [1 2 3 5 2 4 1 1 1]
  
  [1, 6],
  [2, 4],
  [3, 3],
  [4, 1],
  [5, 5],
  [6, 2],
  [7, 7],
  [8, 8],
  [9, 9]
  </code></pre>
  <p>if more than one unique have same appearance than the smallest unique come first, in this example wherever there is one it should be replace by 6, 2 should be replace by 4, 3 remain 3, 4 should be replace by 1, 5 stay 5, 6 become 2, and so on.</p>
  <p>I have arrays of 10000*10000 and about 8000 unique so it cannot be manually and should be fast.</p>
  <p>If it is to problematic the order of same value does not have to be from smallest to biggest must be consistent with the correct main order, meaning that 2 can transfer to 5, and 5 can transfer to 4</p>