- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有以下要矢量化的 for 循环。但是,在 for 循环中我使用了 circshift。有没有办法使用矢量化执行 for 循环,或者至少对其进行优化?随着 strt、stop 和 M 增加它们的大小,它运行得非常慢。
indx = 0;
M = magic(16);
v = M(:,1);
strt=-5;
stop=+5;
result = zeros(4, length(strt:stop), 4);
for ii=strt:stop
tmp = circshift(M, [0 ii])*v;
tmp = tmp/norm(tmp);
indx = indx+1;
result(:, indx, :) = reshape( tmp(:,1), 4,4);
end
最佳答案
用 circshift
移动那个巨大的 2D
数组,M
肯定会很昂贵。因此,一个技巧可能是围绕 1D
数组 v
向另一个方向移动,并保持 M
不变。所以,我们只需要一个编辑来替换:
circshift(M, [0 ii])*v
和 M*circshift(v,-ii)
。
M
的运行时为 (2500 x 2500)
大小的数组,在我这边原始和建议的方法是 -
----------------------- With Original approach
Elapsed time is 0.803823 seconds.
----------------------- With Proposed approach
Elapsed time is 0.137444 seconds.
关于performance - MATLAB:向量化包含 circshift 的 for 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39598263/
我正在尝试将 fftshift/ifftshift 与循环移位联系起来。 N = 5 Y = 0:N-1 X = [0 1 2 3 4] 当我 fftshift(X) 时,我得到 [3 4 0 1 2
我正在尝试使用 find 命令在数字的特定索引处启动 circshift 我该怎么做?请参阅下面的示例代码 %test find and circshift a=[3:2:11] %find inde
1) 我正在尝试同时将数组的(外部单元格)第一个和最后一个单元格向内 移动。这是我尝试对数组执行的操作的内部动画 inward animation .正如您所看到的,外部细胞同时向内(从末端)移动 这
我有以下要矢量化的 for 循环。但是,在 for 循环中我使用了 circshift。有没有办法使用矢量化执行 for 循环,或者至少对其进行优化?随着 strt、stop 和 M 增加它们的大小,
在 Matlab 代码中,我使用了 circshift函数,OpenCV有没有类似Matlab中circshift的函数? 最佳答案 它还没有在代码库中实现,但是有人提交了 version .有一个指
我是一名优秀的程序员,十分优秀!