【问题标题】:separating lists by continuity of integers通过整数的连续性分隔列表
【发布时间】:2013-02-16 07:24:23
【问题描述】:

我想知道是否有人可以帮助我找出一种从某些 xy 数据集中获取与峰值相关的 x 索引的好方法。 我知道 d2y/dx20。但我想将数据从拐点到拐点作为一个列表。 (所以列出一个列表,因为我需要获得几个峰值)

所以,我也能够为拐点到拐点的值列表提出这个:

inflection_indices = [x for x in list( np.where( dY2dX2 < 0.0 )[0] )]

但是,这只是给了我一个所有峰的列表。

我想要一个列表列表,其中整个列表的每个元素都是一个单独的峰值。

像这样:[14,15,16,17,18,19,20,89,90,91,92,93,94,204,205,206,207]

当我想要这个时:[ [ 14,15,16,17,18,19,20] , [89,90,91,92,93,94] , [204,205,206,207] ]

感谢您对此的任何帮助,我将不胜感激。

编辑:我完全删除了所有元组等,因此我可以稍后添加它们,我认为这个问题现在更成为问题的核心。

【问题讨论】:

  • 我没试过,但可能是inflection_indices = [(x,) for x in list( np.where( dY2dX2 &lt; 0.0 )[0] )]。注意括号和逗号
  • 不完全是,加法只是将每个整数放入自己的元组中,如下所示:[(1,), (2,), (3,), (4,), (5,)]
  • 如果你能提供一个样本来使用它肯定会有所帮助。我认为你需要几个步骤。也许您可以使用 np.diff(np.where( dY2dX2 a 中获取它所在的索引!= 1。然后,您将使用 a[:len(a)-1]-1 和 a[2:] 创建开始/结束索引,并使用它们创建切片。沿着这条线的东西。
  • a[:len(a)-1] 是做什么的?这与一维列表的 a[-1] 不一样吗?

标签: python list math tuples signal-processing


【解决方案1】:

我想我找到了答案,但它一点也不优雅......

self.list_of_peak_indeces = [x for x in list(np.where(self.dY2dX2 < 0.0)[0])]
temp_list = []
self.main_lists_of_peak_indices = []
difference_between_indices = np.hstack([np.diff(self.list_of_peak_indeces), np.diff(self.list_of_peak_indeces)[-1]+1])
    for index, item in enumerate(self.list_of_peak_indeces):
        if(np.absolute(difference_between_indices[index])!=1):
            if(temp_list!=[]):
                temp_list.append(item)
                self.main_lists_of_peak_indices.append(temp_list)
            temp_list = []
        else:
            temp_list.append(item)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-10
    • 1970-01-01
    • 1970-01-01
    • 2015-11-11
    • 2011-06-14
    • 1970-01-01
    相关资源
    最近更新 更多