如何在下面找到连续的点及其索引。
我有数据点的列表,我要查看它们是否高于某个阈值。
我可以计算出高于阈值的总点的百分比,但是我需要索引和所有点以上的点。例如
points_above_threshold = [1,1,1,1,0,0,0,1,1] 1是是,0是不,
我需要一个返回的函数,格式点数: [line_points,[start_index,end_index],
例如points_above_threshold的输出 [3,(0,2)],[2,(6,7)]
I have lists of data points, which I look at to see if they are above a certain threshold.
I can calculate the percentage of total points above the threshold, but I need index and points of all points above the threshold. e.g.
points_above_threshold = [1,1,1,0,0,0,1,1]
1 is yes, 0 is no
I need a function which returns, points in the format:
[line_points,[start_index, end_index]
e.g. the output of points_above_threshold would be
[3,(0,2)],[2,(6,7)]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题是缺乏有关您正在使用的数据格式的一些细节。一个好的起点是精确指定功能的预期输入和输出。
例如,如果您的数据是这样的数字列表(浮点):
您的阈值是单个浮点数,并且您的输出预计将是类似的元组列表(索引,data_point):
然后,您可以编写一个看起来像这样的功能:
我将尝试回答如何实现您描述的
points_above_threshold
函数。我们可以使用跟踪系统稍微更改上述函数,以计算以下阈值高于阈值的索引范围:如果我们将此函数应用于具有给定阈值的数字列表,它将以您的方式输出范围上面描述。例如,如果输入列表是简单的示例
[1,1,1,1,0,0,0,1,1]
,则阈值表示
0.5
,则输出为[(3,(0,2)),(2,(6,7))
Your question is lacking some detail about the format of the data you're working with. A good starting point is to specify precisely the expected input and output for your function.
For example, if your data is a list of numbers (floats) like this:
your threshold is a single floating point number, and your output is expected to be a list of tuples (index, data_point) like this:
Then you can write a function that that looks something like this:
I'll attempt to answer how to implement the
points_above_threshold
function you describe. We can alter the above function slightly with a tracking system to calculate the index ranges of values that are above the threshold like this:If we apply this function to a list of numbers with a given threshold, it will output the ranges in the way you describe above. For example, if the input list is the simple example
[1,1,1,0,0,0,1,1]
and the threshold is say
0.5
, then the output is[(3, (0, 2)), (2, (6, 7))]
使用
枚举
和成对迭代
我们可以实现所需的目标。希望这很有帮助!
Using
enumerate
andpairwise iteration
we can achieve what you want.Hope this is helpful!