title: Sorting elements in a np.array using constrains
body: <p>I want to sort a np.array in a certain order f.i. I have input array a: </p>
  
  <pre><code>a = np.array([[ 2,  2,  1,],
                [ 3,  3,  3,],
                [ 2,  3,  2,]])
  </code></pre>
  
  <p>and I want to get for the output:</p>
  
  <pre><code>b = np.array([[ 2,  3,  2,],
                [ 3,  1,  3,],
                [ 2,  3,  2,]])
  </code></pre>
  
  <p>as you may probably guess, the idea for this sorting is to make a <em>symmetry</em> in the array (and plus other stuff, which is not relevant here).</p>
  
  <p>My issue is I'm doing just the random shuffle in order to sort the array:</p>
  
  <pre><code>iNumbers = 0
  while !symmetry(a) and iNumbers != 3000:
        np.random.shuffle(a.flat)
        iNumbers += 1
  </code></pre>
  
  <p>where <code>symmetry</code> function is True if the arrangement of elements is matched the criteria.  </p>
  
  <p>So, I am looking for more efficient ways to sort arrays in order to pass my evaluation function. </p>
  
  <p>Should I apply machine learning techniques to my issue?</p>
  
  <p>Also, I'm looking for any suggestion, remark, idea or thought...</p>