作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个数据框
id lat long
1 12.654 15.50
2 14.364 25.51
3 17.636 32.53
5 12.334 25.84
9 32.224 15.74
L1 = [11.344,7.234]
id lat long distance
1 12.654 15.50
2 14.364 25.51
3 17.636 32.53
5 12.334 25.84
9 32.224 15.74
dist = math.hypot(x2 - x1, y2 - y1)
最佳答案
使用矢量化方法
In [5463]: (df[['lat', 'long']] - np.array(L1)).pow(2).sum(1).pow(0.5)
Out[5463]:
0 8.369161
1 18.523838
2 26.066777
3 18.632320
4 22.546096
dtype: float64
In [5468]: df['distance'] = df[['lat', 'long']].sub(np.array(L1)).pow(2).sum(1).pow(0.5)
In [5469]: df
Out[5469]:
id lat long distance
0 1 12.654 15.50 8.369161
1 2 14.364 25.51 18.523838
2 3 17.636 32.53 26.066777
3 5 12.334 25.84 18.632320
4 9 32.224 15.74 22.546096
np.linalg.norm
向量范数。
In [5473]: np.linalg.norm(df[['lat', 'long']].sub(np.array(L1)), axis=1)
Out[5473]: array([ 8.36916101, 18.52383805, 26.06677732, 18.63231966, 22.5460958 ])
In [5485]: df['distance'] = np.linalg.norm(df[['lat', 'long']].sub(np.array(L1)), axis=1)
关于python - 在 Pandas 数据框中查找从点到行的欧几里德距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46908388/
我有一个 C# 应用程序和一个 SQL Server 数据库。我在记事本中收到了一些文件,其中一列是用 Reed-Solomon 算法加密的。 有人能告诉我如何使用 Reed-Solomon 算法解码
我有一个 28 字节的序列,据说是用 Reed-Solomon (28, 24, 5) 代码编码的。 RS 码使用 8 位符号并在 GF(28) 中运行。场生成多项式为 x8+x4+x3+x2+1。我
我是一名优秀的程序员,十分优秀!