小编Kie*_*108的帖子

在Matlab / Python中向量化多个for循环

我正在尝试对数学模型进行编码,它涉及在数千个具有变化的模型参数的值网格上计算特定数量。目前,这太慢了,我正在寻找有关向量化模型中最密集部分的建议。

为了便于阅读,我目前已经有了它的基本实现,但是现在如果可能的话,希望对下面的整个代码段进行矢量化处理。该代码段的一个最小示例是:

% Setup grid to evaluate and results vector
T_max = 10000;
eval_points = linspace(0, T_max, 1000);
results = zeros(size(eval_points));
% Function that is used in computation
Z_func = @(x, omega) (1./(omega.*sqrt(2*pi))).*exp( -(x.^2)./(2.*omega.*omega) );
% Random data for now, known in full problem
historic_weights = rand(1,100);
historic_times   = rand(1,100);
% Fixed single parameter omega
omega            = 0.5;
% Time evaluation
tic()
for eval_counter = 1:size(eval_points,2)
    for historic_counter = 1:size(historic_weights,2)
    temp_result = 0;
        for k = 0:1:T_max
            temp_result = temp_result …
Run Code Online (Sandbox Code Playgroud)

performance matlab vectorization

2
推荐指数
1
解决办法
62
查看次数

标签 统计

matlab ×1

performance ×1

vectorization ×1