How to apply a function to each column of a 3D array?
3 次查看(过去 30 天)
显示 更早的评论
I have a function that works on a vector (call it "test_f") and gives as output a vector. I want to apply it to each column of a 3D array ( example A= randn(10,10,10)), without using a loop. Is it possible?
回答(1 个)
Joss Knight
2018-1-18
There isn't anything supported for gpuArray that can take any generic user function in this way. If test_f contains operations supported by pagefun then you could break it down into multiple calls to that. Or convert your array to a cell array ( mat2cell(A, 10, ones(10,1), ones(10,1) ) and process it using cellfun.
4 个评论
Joss Knight
2018-2-7
Your expectations for the capabilities of a GPU are misguided in this case. There's almost nothing a GPU can do on 100 values faster than the CPU. You need to give it more data. One way is to vectorize your code, which means working out how to formulate the equations so that all the data is processed at once. I can't help you do that as long as I've no idea what test_mat is doing.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 GPU Computing in MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!