日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java 移动其他窗口_移动窗口平均值不等

發布時間:2023/12/2 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 移动其他窗口_移动窗口平均值不等 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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 移动其他窗口_移动窗口平均值不等的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。