sort numpy array elements by the value of a condition on the elements
<p>I need to sort a numpy array of points by increasing distance from another point.</p>

<pre><code>import numpy as np

def dist(i,j,ip,jp): 
    return np.sqrt((i-ip)**2+(j-jp)**2)

arr = np.array([[0,0],[1,2],[4,1]])
</code></pre>

<p>What I would like to do is use function dist(1,1,ip,jp) between a fixed point [i,j]=[1,1] and each ordered pair [ip,jp] in arr to return arr with each element sorted from lowest to highest proximity to [i,j]. Anyone have a quick solution for this? </p>

<p>The output I want is new_arr = np.array([[1,2],[0,0],[4,1]])</p>

<p>I have some ideas but they're wildly inefficient seeming. </p>

<p>Thanks!</p>