Ad
Code
Diff
  • import numpy as np
    
    # calculate the distance between two points in 2d,3d ... nD
    def distanceND(pA, pB, nD = None):
        return np.linalg.norm(np.array(pA) - np.array(pB))
    
    distance2D = distanceND
        
    distance3D =distanceND
    
    
    • from math import sqrt, pow
    • import numpy as np
    • # calculate the distance between two points in 2d,3d ... nD
    • def distanceND(pA, pB, nD = None):
    • return sqrt(sum(pow(a-b,2) for a,b in zip(pA,pB)))
    • return np.linalg.norm(np.array(pA) - np.array(pB))
    • distance2D = distanceND
    • distance3D =distanceND