How do I transpose a matrix?

How do I transpose a matrix in GAMS?

You can transpose a matrix by assignment or using the projection operator. See the following example:

Set i /i1*i2000/,
    j /j1*j2000/;

Parameter w(i,j),
          transw1(j,i),
          transw2(j,i);

* Generate some random data
w(i,j)= uniformInt(0,5);

* Activate performance profiling
Option profile=1;

* Version 1: Assignment
transw1(j,i)=w(i,j);

* Version 2: Using the projection operator
option transw2 < w;

Looking at the performance profile, the projection is about 4 times quicker than the assignment:

----     15 Assignment transw1       0.797     1.219 SECS    298 MB  3334217
----     18 Other                    0.187     1.406 SECS    324 MB