【问题标题】:Selecting the maximum value for a certain time interval [duplicate]选择某个时间间隔的最大值[重复]
【发布时间】:2020-01-13 06:56:16
【问题描述】:

我想在某个时间间隔后选择最大值/最小值。类似于滑动或滚动窗口但计算部分中的最大值/最小值的东西。这里是一个例子 [6 3 7 4 6 9 2 6 7 4 3 7 8 2 5 4 1 7 5 1]。在这种情况下,我希望窗口计算前 5 个值的最大值,然后计算下一部分的最大值(索引 6 到 10)等等。

select a max value 7 from this portion [6 3 7 4 6]
select a max value 9 from this portion [9 2 6 7 4] 
select a max value 8 from this portion [3 7 8 2 5] 
select a max value 7 from this portion [4 1 7 5 1] 

关于如何做的任何想法。某种功能也可以让我调整窗口长度,即 5 到 3。提前致谢

【问题讨论】:

  • @ sshashank124 据我了解,他们在滚动窗口中询问,而他们的示例中恰好没有重叠。

标签: python numpy


【解决方案1】:

你可以重塑numpy数组,然后得到最大值

>>> arr = np.array([6, 3, 7, 4, 6, 9, 2, 6, 7, 4, 3, 7, 8, 2, 5, 4, 1, 7, 5, 1])
>>> arr = arr.reshape(-1,5)
>>> arr.max(axis=1)
array([7, 9, 8, 7])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-01
    • 2016-09-11
    • 2018-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多