用圆而不是矩形的binning 2D数据 - 来自熊猫DF

发布于 2025-01-29 01:26:30 字数 384 浏览 2 评论 0原文

我有一个X,Y数据的数据框,需要将其汇成圆圈。即一定尺寸的圆圈和间距以某个点为中心。因此,例如,在此采样/binning之后将遗漏一些数据。怎么可能?

我尝试了np.histogram2d并创建蒙版/广播。面具太慢了,我似乎无法广播圆圈。仅通过以下答案判断该点是否在圆圈的上述网格之内:将2D数据纳入x,y 中的重叠圆。

如果有一种方法可以将边缘或其他方法输入直方图2D并使边缘循环,请告诉我。干杯

I have a dataframe of x, y data and need to bin it into circles. Ie a grid of circles of certain size and spacing centered on some point. So for example some data would be left out after this sampling/binning. How is this possible?

I have tried np.histogram2d and creating masks/broadcasting. The mask was too slow, and I don't seem able to broadcast into a circle. Only to tell if the point is within said grid of circles via this answer: Binning 2D data into overlapping circles in x,y.

If there is a way to input edges or something into histogram2d and make the edges circular please let me know. Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

和我恋爱吧 2025-02-05 01:26:30

这可以做到的唯一方法是将您的观点和网格循环循环:这样:

def inside_circle(x, y, x0, y0, r):
    return (x - x0)*(x - x0) + (y - y0)*(y - y0) < r*r


x_bins = np.linspace(-9, 9, 30)
y_bins = np.linspace(-9, 9, 30)

h = df['upmm']
w = df['anode_entrance']

histo = np.zeros((32,32))

for i in range(0, len(h)):
    for j in range(0, len(x_bins)):
        for k in range(0, len(y_bins)):
            if inside_circle(h[i], w[i], x_bins[j], y_bins[k], 0.01):
                histo[j][k] = histo[j][k] + 1
            
plt.imshow(histo, cmap='hot', interpolation='nearest')
plt.show()

The only way this can be done is by looping over your points and grid of circles like so:

def inside_circle(x, y, x0, y0, r):
    return (x - x0)*(x - x0) + (y - y0)*(y - y0) < r*r


x_bins = np.linspace(-9, 9, 30)
y_bins = np.linspace(-9, 9, 30)

h = df['upmm']
w = df['anode_entrance']

histo = np.zeros((32,32))

for i in range(0, len(h)):
    for j in range(0, len(x_bins)):
        for k in range(0, len(y_bins)):
            if inside_circle(h[i], w[i], x_bins[j], y_bins[k], 0.01):
                histo[j][k] = histo[j][k] + 1
            
plt.imshow(histo, cmap='hot', interpolation='nearest')
plt.show()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文