나는 유클리드 거리로 정렬해야하는 몇 개의 복소수를 가지고 있습니다. 이 문제는 다음과 같이 해결합니다.파이썬에서 유클리드 거리로 복소수를 정렬하는 효율적인 방법
# 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