【问题标题】:Select data based on histogram count根据直方图计数选择数据
【发布时间】:2020-12-23 08:06:10
【问题描述】:

亲爱的:我有一组二维数组,如下所示。前3列是点的xyz坐标,第三列是点到中心的距离。

array([[-1.01742668e+01,  6.89185798e-01,  1.17535509e-01,
         2.02460059e+03],
       [-1.00412054e+01,  6.97973669e-01, -5.14677428e-02,
         2.02460887e+03],
       [-9.89616013e+00,  6.80048764e-01,  1.06134348e-01,
         2.02459041e+03],
       ...,
       [-9.60342407e+01, -2.03417969e+00, -3.64747904e-02,
         2.02402794e+03],
       [-9.71151733e+01, -2.02474523e+00,  5.34135802e-03,
         2.02408764e+03],
       [-9.60278931e+01, -2.04594707e+00, -4.45659012e-02,
         2.02401589e+03]])

我绘制了一个如下所示的直方图。

我想知道有什么方法可以删除与红圈中的 bin 相关联的数据点?

目前我尝试的是以下代码。

c_dist=np.asarray(c_dist)

hist, bins = np.histogram(c_dist[:,3], bins=100)
# Threshold frequency
freq = 100

# Zero out low values
hist[np.where(hist <= freq)] = 0
# Plot
width = 0.7 * (bins[1] - bins[0])
center = (bins[:-1] + bins[1:]) / 2
plt.bar(center, hist, align='center', width=width)
# plt.yticks(np.arange(min(hist), max(hist)+1, 10))
plt.title("Center to Point Distance")
plt.xlabel("Distance")
plt.ylabel("Count")

d = np.digitize(c_dist[:,3], bins)

得到下图。

但是,该方法似乎只删除了图中不需要的 bin,无法删除原始数据集中的关联数据点。

谁能帮我解决这个问题?非常感谢您的大力帮助和支持。

【问题讨论】:

  • 您的意思是无法删除关联的数据点??您已将它们归零。您要删除它们吗?
  • 您正在编辑基于频率过滤器的hist 数组。如果要编辑原始数据,请过滤c_dist 数组。此外,请遵循指南并提供mive

标签: python numpy matplotlib


【解决方案1】:

如果你的意思是它们是零并且你想删除 而不是:

hist[np.where(hist <= freq)] = 0

执行以下操作:

hist = hist[hist <= freq]

【讨论】:

  • 亲爱的@adir abargil。抱歉我的解释不好,请让我再试一次。我想要的是找到包含在 bin 中的数据点(c_dist[:, 3])(红色圆圈)并将它们从原始数据集(c_dist)中删除
  • 你能发布原始数据集吗?或更简单,只需尝试其他解决方案
【解决方案2】:

我猜你想根据第三列从c_dist 中删除行。如果这是您需要的,请考虑以下玩具数据示例:

import numpy as np

c_dist = np.random.randint(0, 10, (10, 4))
th_freq = 4

c_dist_clean = c_dist[c_dist[:, 3] >= th_freq]

最后一行选择c_dist中第三列值超过th_freq的行,复制到c_dist_clean

【讨论】:

  • 亲爱的@MaxPowers。抱歉我的解释不好,请让我再试一次。我想要的是找到包含在 bin 中的数据点(c_dist[:, 3])(红色圆圈)并将它们从原始数据集(c_dist)中删除
猜你喜欢
  • 2018-10-21
  • 2013-10-13
  • 2013-11-26
  • 1970-01-01
  • 2023-03-04
  • 1970-01-01
  • 2011-09-17
  • 2017-12-08
相关资源
最近更新 更多