ユークリッド距離でソートする必要がある複素数がいくつかあります。Pythonでユークリッド距離で複素数をソートする効率的な方法
# A1x = Lowest Point (LP)
# B1x = Point 1 (P1)
# B4x = Point 2 (P2)
C1 = euclidean(A1x, B1x) # Build the distance between LP and P1
C4 = euclidean(A1x, B4x) # Build the distance between LP and P2
array = np.array([C1, C4]) # Put the distances into an array...
array.sort() # ...and sort it.
# If the the distance between LP and P1 is the first element in the array
# then take P1 as y_max value etc.
if C1 == array[0]:
y_max = B1x
if C4 == array[1]:
y_min = B4x
if C4 == array[0]:
y_max = B4x
if C1 == array[1]:
y_min = B1x
この方法では、3つのまたは4つのポイントに適しています:私はこのように、この問題を解決します。しかし、今私は8または9ポイントを得て、上記の方法はちょっと厄介になります。なぜなら、すべての単一ポイントに対してif条件を書く必要があるからです。したがって、ユークリッド距離で複素数をソートするより良い方法が分かっているかどうか聞いてみたいと思います。
まず、遅れて返信して申し訳ありません!このメソッドの私の問題は、私はあなたの例のように一つの配列 "B"に異なる配列を置くことができないということでした。しかし、 "dist = np.linalg.norm(B-Ap、ord = 2、axis = 1)"という行は正しいパスに設定されています。 と "sorted_B = B [np.argsort(dist)]"ご助力ありがとうございます!! – petermailpan