How can the Euclidean distance be calculated with NumPy?

后端 未结 22 906
春和景丽
春和景丽 2020-11-22 02:29

I have two points in 3D:

(xa, ya, za)
(xb, yb, zb)

And I want to calculate the distance:

dist = sqrt((xa-xb)^2 + (ya-yb)^2 + (         


        
22条回答
  •  既然无缘
    2020-11-22 02:53

    I find a 'dist' function in matplotlib.mlab, but I don't think it's handy enough.

    I'm posting it here just for reference.

    import numpy as np
    import matplotlib as plt
    
    a = np.array([1, 2, 3])
    b = np.array([2, 3, 4])
    
    # Distance between a and b
    dis = plt.mlab.dist(a, b)
    

提交回复
热议问题