TL;DR: 无论如何我可以摆脱我的第二个 for -loop?

我在2D网格上有一系列时间点 . 为了消除它们位置的快速波动,我在一个帧窗口上平均坐标 . 现在在我的情况下,它想要包含特定点的帧,如果它的行程比 cut_off 值更远 .

在第一个 for -loop中,我遍历所有帧并定义移动窗口 . 然后,我计算当前帧与移动窗口中每个帧之间的距离 . 在我从所有帧中仅抓取那些位置后, x 和 y 组件的行程都没有超过 cut_off . 现在我想计算移动窗口所有这些选定帧中每个点的平均位置( note: 所选帧的数量可以小于 n_window ) . 这导致我第二个 for -loop . 在这里,我迭代所有点并实际 grab 帧中的位置,其中当前点没有比 cut_off 传播更远 . 从这些选定的帧中,我计算坐标的平均值,并将其用作当前帧的新值 .

这最后 for -loop减慢了整个处理过程 . 我无法想出一个更好的方法来完成这个计算 . 有什么建议?

MWE

提出评论以澄清 .

import numpy as np

# Generate a timeseries with 1000 frames, each

# containing 50 individual points defined by their

# x and y coordinates

n_frames = 1000

n_points = 50

n_coordinates = 2

timeseries = np.random.randint(-100, 100, [n_frames, n_points, n_coordinates])

# Set window size to 20 frames

n_window = 20

# Distance cut off

cut_off = 60

# Set up empty array to hold results

avg_data_store = np.zeros([n_frames, timeseries.shape[1], 2])

# Iterate over all frames

for frame in np.arange(0, n_frames):

# Set the frame according to the window size that we're looking at

t_before = int(frame - (n_window / 2))

t_after = int(frame + (n_window / 2))

# If we're trying to access frames below 0, set the lowest one to 0

if t_before < 0:

t_before = 0

# Trying to access frames that are not in the trajectory, set to last frame

if t_after > n_frames - 1:

t_after = n_frames - 1

# Grab x and y coordinates for all points in the corresponding window

pos_before = timeseries[t_before:frame]

pos_after = timeseries[frame + 1:t_after + 1]

pos_now = timeseries[frame]

# Calculate the distance between the current frame and the windows before/after

d_before = np.abs(pos_before - pos_now)

d_after = np.abs(pos_after - pos_now)

# Grab indices of frames+points, that are below the cut off

arg_before = np.argwhere(np.all(d_before < cut_off, axis=2))

arg_after = np.argwhere(np.all(d_after < cut_off, axis=2))

# Iterate over all points

for i in range(0, timeseries.shape[1]):

# Create temp array

temp_stack = pos_now[i]

# Grab all frames in which the current point did _not_

# travel farther than `cut_off`

all_before = arg_before[arg_before[:, 1] == i][:, 0]

all_after = arg_after[arg_after[:, 1] == i][:, 0]

# Grab the corresponding positions for this points in these frames

all_pos_before = pos_before[all_before, i]

all_pos_after = pos_after[all_after, i]

# If we have any frames for that point before / after

# stack them into the temp array

if all_pos_before.size > 0:

temp_stack = np.vstack([all_pos_before, temp_stack])

if all_pos_after.size > 0:

temp_stack = np.vstack([temp_stack, all_pos_after])

# Calculate the moving window average for the selection of frames

avg_data_store[frame, i] = temp_stack.mean(axis=0)

java 移动其他窗口_移动窗口平均值不等相关推荐

  1. qt如何把父窗口的变量传给子窗口_父窗口和iframe子窗口之间相互传递参数和调用函数或方法...

    1.父窗口向子窗口传递参数: 可以在url中添加参数:2.html?a=1&b=2&c=3 然后在子页面上可用js解析,提供一个函数: function getQueryStr(sAr ...

  2. java同时关闭两个窗口_在一个窗口中同时关闭多个窗口的问题(Swing中事件多点传送的问题) | 学步园...

    class   A{} A中包含有: JFrame   frameA; JButton   btnA; class   B{} B中包含有: final   JFrame   frameB; Stat ...

  3. java图形界面包_抽象窗口工具包( )是java提供的建立图形用户界面GUI的开发包

    抽象窗口工具包( )是java提供的建立图形用户界面GUI的开发包 劈指是用大指弹奏的.A:对B:错 要保证权利与义务相对等,寿险保费的计算就必须遵循收支平衡的原则.A:对B:错 抽样平均误差的实质是 ...

  4. mysql 浏览器可视窗口_浏览器窗口的可视区域大小指的是哪里?

    可视区域就是:你可以看到的区域. 浏览器窗口显示网页的部分(即不包括地址栏.工具栏)就是可视区.. 你可以用鼠标来推动浏览器窗口来改变大小,此时可视区的大小也是跟着变的.. 下面送一份我总结的与可视区 ...

  5. python悬浮球窗口_悬浮窗口(智能隐藏和显示)的一种实现方案

    悬浮窗口应该具有的特性 为了实现让用户能方便打开软件主窗口,又不对用户界面造成明显的视觉干扰,悬浮窗口应该有以下特点: 和主窗口是二选一的关系,主窗口显示时自动隐藏,主窗口被全部遮挡时自动显示 始终置 ...

  6. python关闭当前窗口 打开新窗口_关闭窗口,用PyQ在Python中打开一个新窗口

    我是PyQt5新手,想编写一个小程序 我在QT设计器中设计了两个窗口,并将它们转换成py脚本. 后来我把两者合并成一个文件(也许我的尝试完全错了-所以请纠正我) 当程序启动时,我会看到一个小窗口,上面 ...

  7. python判断当前激活窗口_多种窗口都可能被激活的情况下判断其中某个是否激活...

    遇到的问题 今天测试 SAP 系统流程的时候突然出现了问题导致无法继续,问题是这样的:在 SAP 查询出结果后需要点击导出为电子表格,点击以后过几分钟会弹出这样的窗口: 然后我只需要检测 " ...

  8. java通过按钮打开新窗口_如何在java程序中,当点击一个按钮后,关闭当前窗口,开启一个新的窗口。...

    JButton btn=new JButton(new AbstractAction("关闭并打开") {      @Override   public void actionP ...

  9. java怎么捕捉游戏窗口_捕捉桌面上的窗口信息

    今天我为大家带来一个有趣的例子,有点像Spy++的功能,通过鼠标在屏幕上移动,并实时捕捉指定坐标点处的窗口信息. 窗口信息包括窗口标题,窗口句柄,窗口类名,以及呈现所捕捉窗口的缩略图. 现在我们不妨来 ...

最新文章

  1. mongo-log参数与config参数
  2. 1.17.Flink 并行度详解(Parallel)、TaskManager与Slot、Operator Level、Execution Environment Level、Client Level等
  3. gpa-user-guide-for-ubuntu-host
  4. 电路基本概念有哪些?
  5. 计算机英语初级考试时间,2020年考研考试时间安排及考试科目_考研网
  6. Atitit 院系和专业规划 大学里的院系,院一般指的都是学院,比如管理学院、法学院这种,系指的就是院里面的专业,比如中文系、哲学系这种。 中文系、哲学系 土木工程 目录 1. 经济管理学院 2
  7. Mysql之wait_timeout参数生效办法
  8. Win7平台上通过QQ查询对方IP地址
  9. 添加最顶层js广告_js实现网站最上边可关闭的浮动广告条代码
  10. 1260.shift-2d-grid
  11. 王船山的哲思深度:五百年来,真通天人之故者,船山一人而已
  12. winpe读取linux硬盘数据恢复,如何在WinPE环境下完成文件恢复
  13. sklearn机器学习(七)决策树预测泰坦尼克号幸存者
  14. 如何用 Roam Research 备课?
  15. 0316复利和单利计算更新4
  16. 计算机毕业设计Java医院管理系统(系统+源码+mysql数据库+Lw文档)
  17. PHP 核心技术与最佳实践
  18. 厚颜无耻的免费使用Visio和project2016
  19. IT 通信类客户分析
  20. Bugzilla的bug状态

热门文章

  1. 具有多个查询参数的Camel CXF服务
  2. Rete之外的生活– RIP Rete 2013 :)
  3. 集成测试CDI 1.0和Spring 3.1中的作用域bean
  4. Servlet中判断浏览器版本的代码
  5. 链表数据结构原理图/内存结构图/内存图
  6. 计算机应用基础本模块一测试,广东开放大学远程教育专科2018年秋计算机应用基础Word模块测试...
  7. linux useradd 数字,详解linux useradd用户组合权限管理等
  8. 【音视频安卓开发 (零)】用 Android NDK 编译 FFmpeg 与 X264
  9. LeetCode 231. 2的幂
  10. axure html尺寸,axure怎么确定尺寸