How can I calculate the distances of a set of 3d points with each other using python?

后端 未结 2 1948
你的背包
你的背包 2021-01-24 11:16

I have a set of 3D points, where I need to find the distances of every point with all other points. So far I came up with the code as below to calculate the distances between tw

2条回答
  •  孤独总比滥情好
    2021-01-24 11:29

    How about two loops instead of one?

    distances = []
    for i in xrange(npoints-1):
        for j in range(i+1, npoints):
            distances.append(np.linalg.norm(x[i]-x[j])
    

提交回复
热议问题