Fastest pairwise distance metric in python

前端 未结 3 1011
天涯浪人
天涯浪人 2020-11-30 06:47

I have an 1D array of numbers, and want to calculate all pairwise euclidean distances. I have a method (thanks to SO) of doing this with broadcasting, but it\'s inefficient

3条回答
  •  执笔经年
    2020-11-30 07:43

    Using half the memory, but 6 times slower than np.abs(r - r[:, None]):

    triu = np.triu_indices(r.shape[0],1)
    dists2 = abs(r[triu[1]]-r[triu[0]])
    

提交回复
热议问题