商户如何做h5商城网站是什么意思,合肥网站建设案例,设计网页多少钱,怎么重新运行wordpressTL;DR: 无论如何我可以摆脱我的第二个 for -loop#xff1f;我在2D网格上有一系列时间点 . 为了消除它们位置的快速波动#xff0c;我在一个帧窗口上平均坐标 . 现在在我的情况下#xff0c;它想要包含特定点的帧#xff0c;如果它的行程比 cut_off 值更远 .在第一个 for -…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 coordinatesn_frames 1000n_points 50n_coordinates 2timeseries np.random.randint(-100, 100, [n_frames, n_points, n_coordinates])# Set window size to 20 framesn_window 20# Distance cut offcut_off 60# Set up empty array to hold resultsavg_data_store np.zeros([n_frames, timeseries.shape[1], 2])# Iterate over all framesfor frame in np.arange(0, n_frames):# Set the frame according to the window size that were looking att_before int(frame - (n_window / 2))t_after int(frame (n_window / 2))# If were trying to access frames below 0, set the lowest one to 0if t_before 0:t_before 0# Trying to access frames that are not in the trajectory, set to last frameif t_after n_frames - 1:t_after n_frames - 1# Grab x and y coordinates for all points in the corresponding windowpos_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/afterd_before np.abs(pos_before - pos_now)d_after np.abs(pos_after - pos_now)# Grab indices of framespoints, that are below the cut offarg_before np.argwhere(np.all(d_before cut_off, axis2))arg_after np.argwhere(np.all(d_after cut_off, axis2))# Iterate over all pointsfor i in range(0, timeseries.shape[1]):# Create temp arraytemp_stack pos_now[i]# Grab all frames in which the current point did _not_# travel farther than cut_offall_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 framesall_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 arrayif 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 framesavg_data_store[frame, i] temp_stack.mean(axis0)