是否有一个相当于R的dist函数的python?

问题描述 投票:0回答:1

教授给了我这个R代码的任务...

# Simulate the error vector
# 
       e <- dist(9,...)

...进入Python。我知道这是距离矩阵计算,所以我在Python上搜索了Google并得到了scipy.spatial.distance_matrix

我在这段代码中用它来尝试匹配R ...

e = sps.distance_matrix([[0,0],[0,9]], [[9,0],[9,9]])

但是我认为输出不正确。

python r distance-matrix
1个回答
-1
投票

使用熊猫

import pandas as pd

col1 = [x+10 for x in range(3)]
col2 = [x+100 for x in range(3)]
df = pd.DataFrame(list(zip(col1,col2)))
print(df)

#RESULT
#    0    1
#0  10  100
#1  11  101
#2  12  102
© www.soinside.com 2019 - 2024. All rights reserved.