arrays - 使用滑动窗口查看 Julia 数组

标签 arrays performance julia rolling-computation sliding-window

使用例如滑动窗口=2 在数组上创建 View 的最有效方法是什么

假设我们有:

x = collect(1:1:6)
# 1 2 3 4 5 6

我想创建一个这样的 View :

# 1 2
# 2 3
# 3 4
# 4 5
# 5 6

到目前为止,我只找到了这个选项,但不确定它是否是最佳选项:

y = Array{Float32, 2}(undef, nslides, window)
@inbounds for i in 1:window
    y[:, i] = @view x[i:end-(window-i)]
end

最佳答案

一个带包的解决方案(嗯,我的包)是这样的:

julia> using Tullio

julia> x = 1:6; window = 2;

julia> @tullio y[r,c] := x[r+c-1]  (c in 1:window)
5×2 Matrix{Int64}:
 1  2
 2  3
 3  4
 4  5
 5  6

关于arrays - 使用滑动窗口查看 Julia 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63769931/

相关文章:

arrays - Python Numpy重复一个arange数组

arrays - 大小大于 2147483647 的 BooleanArray

python - 在 numpy 数组中找到最大上三角项的索引的有效方法?

asynchronous - Julia:了解何时发生任务切换

php - 在不影响内存限制的情况下导入巨大的 JSON 编码数组

javascript - 在javascript中进行左外连接

performance - 有没有更快的方法来绕圈移动东西?

javascript - 在 html 中加载 javascript 的理想位置在哪里?

r - Julia 中的完美(或接近)多重共线性

macros - 为什么 Julia 中的字符串宏使用...?