python怎么撤销到上一行_Python:根据上一行的最后一个元素和后一行...

作为标题,假设我得到了一个(n,2)numpy数组,该数组记录了一系列段的开始和结束索引,例如n = 6:

import numpy as np

# x records the (start, end) index pairs corresponding to six segments

x = np.array(([0,4], # the 1st seg ranges from index 0 ~ 4

[5,9], # the 2nd seg ranges from index 5 ~ 9, etc.

[10,13],

[15,20],

[23,30],

[31,40]))

现在,我想以较小的间隔合并这些段.例如,如果间隔不大于1,则合并连续的段,因此所需的输出将是:

y = np.array([0,13], # Cuz the 1st seg's end is close to 2nd's start,

# and 2nd seg's end is close to 3rd's start, so are combined.

[15,20], # The 4th seg is away from the prior and posterior segs,

# so it remains untouched.

[23,40]) # The 5th and 6th segs are close, so are combined

这样输出段就会变成三个,而不是六个.

任何建议,将不胜感激!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值