help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Two arrays specifying index pairs for a another array -- how to vectoriz


From: Jason
Subject: Two arrays specifying index pairs for a another array -- how to vectorize?
Date: Fri, 12 Mar 2010 19:06:02 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Hello,

I have a 2D array, say 'A'.  I also have two 2D arrays, say 'ix' and 'iy'.  I
would like to make a third 2D array, whose elements are the elements of A at the
index pairs specified by ix and iy.  I can do this with a loop as follows:

    for i=1:nx
        for j=1:ny
            out(i,j) = A(ix(i,j),iy(i,j));
        end
    end

Is there a way I can do this with matrix/vector operations? If I do
out=A(ix,iy), that will give me an (nx*ny)X(nx*ny) array using all the possible
pairs of values in ix and iy.  Any ideas?

Thank you,
Jason



reply via email to

[Prev in Thread] Current Thread [Next in Thread]