Can I somehow optimize this formula? I evaluate it many times and it takes much time...
w
- 1xN double
phis
- NxN double
x
- Nx2 double
开发者_C百科sum(w(ones([size(x, 1) 1]),:) .* phis, 2)
You're taking the scalar product of each row of phis
with w
. You can do this easily using linear algebra.
out = phis * w';
This matrix multiplication saves you calls to sum
, ones
, and size
, which should make your code a lot faster. Furthermore, linear algebra operations are often very fast in Matlab, since that's what the program is historically optimized for.
精彩评论