Alternative to reshape to multiply multidimensional arrays
Show older comments
I am working on a dynamic programming problem and after profiling my code I noticed that most of the computing time is spent using the reshape function to quickly multiply a value function by a probability array. This is faster than using for loops but not fast enough. The line using the reshape function takes almost 50% of the total computation time. Any suggestions would be very appreciated. Please let me know if the description/code is not clear. Thank you.
no_obs = 210;
EV = zeros(no_obs,4);
next_age = [9;1;1;1];
Vinit(pr1,pr2,pr3,next_age,action,no_obs)
for action=1:4
V = reshape(Vinit(:,:,:,next_age(action),action,:),[],no_obs);
EV(:,action)=(P_array(:).' * V).';
end
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!