arrays - Indexing into N-D matrix -


i have matrix m (4*2) values:

[1 0;  0 0;  1 1;  0 1] 

and array x = [0.3 0.4 0.5 0.2];

all column entries of m binary (0/1). want corresponding row value mapped nd-array of [2,2] called z. each dimension here indicates 0/1, having in first row or second row. x(1) needs go z(2,1) , x(2) needs go z(1,1) , on..

z this:

z =  [0.4 0.2;  0.3 0.5]; 

currently looping on this, expensive so. please note minimal example - need 128*7 matrix 7d array.

any suggestions on how speed process?

you try using accumarray (not sure if it's faster):

>> z = accumarray(m + 1, x, [2 2])  z =      0.4000    0.2000     0.2000    0.5000 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -