- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个带有坐标(X,Y)的数据框,我需要获取一个包含最高密度点坐标的列表。
我使用坐标(X,Y)的平均值并计算从该点到所有其他点的距离,然后对它们进行排序,但平均值并不总是在最密集的点。使用 gaussian_kde 我可以可视化最密集的点,但我不知道如何将点提取到列表中。
import numpy as np
import pandas as pd
import pylab as plt
import random
from scipy.stats import gaussian_kde
from scipy.spatial.distance import cdist
from scipy.spatial import distance
def closest_point(point, points):
""" Find the nearest point. """
return points[cdist([point], points).argmin()]
x = [random.randint(0, 100) for x in range(1, 51)]
y = [random.randint(0, 100) for x in range(1, 51)]
fr = pd.DataFrame({'x':x,'y':y})
mx = fr['x'].mean()
my = fr['y'].mean()
fr2 = pd.DataFrame({'x':[mx],'y':[my]})
fr['Punto'] = [(x, y) for x,y in zip(fr['x'], fr['y'])]
fr2['Punto'] = [(x, y) for x,y in zip(fr2['x'], fr2['y'])]
fr2['Cercano'] = [closest_point(x, list(fr['Punto'])) for x in fr2['Punto']]
lista = fr['Punto'].tolist()
media = fr2['Punto'].tolist()
distancia_numpy = distance.cdist(lista,media, 'euclidean')
distancia_lista = np.array(distancia_numpy).tolist()
distancia_serie = pd.Series(distancia_lista)
"""
we place a new column with the distance from the average point to the nearest point
"""
fr['Distancia'] = distancia_serie
ordenado = fr.sort_values('Distancia', ascending = True)
xy = np.vstack([x,y])
z = gaussian_kde(xy)(xy)
fig, ax = plt.subplots()
ax.scatter(x, y, s=50, c=z, edgecolor='')
"""in red the mean of the points"""
ax.scatter(mx, my, s=100,c='red', edgecolor='')
plt.show()
print (ordenado)
结果应该是一个列表或一个有序的数据帧,首先具有最密集的点,事实上我得到了这些结果,但它们不正确,因为平均点不位于最大密度的点。非常欢迎任何帮助
最佳答案
非常感谢!这段代码完成了工作!
point_gaus = pd.DataFrame({'x':x,'y':y,'gauss':list(z)})
point_gaus_order = point_gaus.sort_values('gauss', ascending = False)
point_gaus_order_10 = point_gaus_order[:10]
ax.scatter(point_gaus_order_10['x'],point_gaus_order_10['y'], s=25,c='red', edgecolor='')
关于python - 我需要获取数据帧最密集点的坐标(x,y),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56526858/
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 5 个月前关
我正在尝试使用摄像机跟踪多个人。我不想使用 blob 分割技术。我想做什么: 执行背景减法以获得隔离人们运动的掩码。 在这些区域执行基于网格的光流 -我最好的选择是什么? 我正在努力实现。我已经尝试过
OpenCV 有 very good documentation on generating SIFT descriptors ,但这是“弱 SIFT”的一个版本,其中关键点由原始 Lowe algo
我有一个 cholmod_dense 数据结构: cholmod_dense* ex = cholmod_l_solve(CHOLMOD_A, L, B, &com); 我想提取这些值并将它们复制到另
这是先前发布的关于在 python 中使用 OpenCVs 密集筛选实现的问题的后续问题 (OpenCV-Python dense SIFT)。 使用建议的代码进行密集筛选 dense=cv2
我是计算机视觉的新手。我正在学习 Dense SIFT 和 HOG。对于密集 SIFT,算法只是将每个点视为一个有趣的点并计算其梯度向量。 HOG 是另一种用梯度向量描述图像的方法。 我认为 Dens
我正在尝试使用 openCV-python 2.4 计算密集 SIFT import cv2 def gen_sift_features(gray, step_size, gamma): de
我正在使用 OpenCV 实现词袋图像分类器。最初我测试了在 SURF 关键点中提取的 SURF 描述符。我听说 Dense SIFT(或 PHOW)描述符更适合我的目的,所以我也尝试了它们。 令我惊
我有一个密集的 Ax=b 类型的方程组要在我的 C++ 程序中求解,我希望在 boost 中使用 UBLAS 来实现该解决方案。在其他一些问题中,我发现人们正在使用扩展 LAPACK,但不幸的是,它似
我目前有一台配备 Opteron 275 (2.2Ghz)(双核 CPU)和 4GB RAM 以及速度非常快的硬盘的机器。我发现即使是使用 C++ 模板(想想 boost 等)编译一些简单的项目时,我
我是一名优秀的程序员,十分优秀!