仅计算 python 中数组中两个元素之间的距离

Calculating distance between two elements only in the array in python

所以我有两个问题:首先,我尝试打印包含 1004 个元素的数组,但它只打印前 29 个元素,然后跳转到 974 继续打印。如何获得包含 1004 个元素的完整数组?

这是我的代码

paired_data = []
for x in data:
    closest, ignored = pairwise_distances_argmin_min(x, result)
    paired_data.append([x, result[closest]])
#print paired_data
S = pd.DataFrame(paired_data, columns=['x','center'])
print S
# distance
Y = pdist(S, 'euclidean')
print Y

另外我想计算数组中每两个元素之间的距离。例如

0 [5, 4] [3, 2]

1 [22, -10] [78, 90]

我想计算 [5, 4] 和 [3, 2] 之间的距离(欧几里德),依此类推数组的所有其余部分。

#1 的另一个解决方案:

print(S.to_string())    # print the entire table

并获取距离

# assumes Python 3
from functools import partial

def dist(row, col1, col2):
    return sum((c2 - c1)**2 for c1,c2 in zip(row[col1], row[col2])) ** 0.5

# compose a function (name the columns it applies to)
s_dist = partial(dist, col1="x", col2="center")
# apply it
S["dist"] = S.apply(s_dist, axis=1)