Azzera filtri
Azzera filtri

Is there faster way of computing loop; max(w .* x); pool; ?

2 visualizzazioni (ultimi 30 giorni)
Mateusz
Mateusz il 18 Dic 2012
Let's assume I have a matrix x \in R[#features, #data] and matrix w \in R[#units, #features]. Currently I am computing max per unit using a loop:
for k=1:numUnits
ww = w(k, :);
tmp = bsxfun(@times, w', x);
r(k, :) = max(tmp, [], 1);
end
Is there any faster, no-loop equivalent version of this code?

Risposte (1)

Andrei Bobrov
Andrei Bobrov il 18 Dic 2012
Modificato: Andrei Bobrov il 18 Dic 2012
r = max(bsxfun(@times,reshape(w',size(w,1),[]),reshape(x,1,size(x,2),[])),[],3);
or
r = max(bsxfun(@times,permute(w,[2 3 1]),permute(x,[3 2 1])),[],3);

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by