How do I transpose a matrix?

Frequently asked questions about GAMS

Moderator: aileen

Forum rules
Please ask questions in the other sub-forums
Locked
aileen
User
User
Posts: 136
Joined: 4 years ago

How do I transpose a matrix?

Post by aileen »

How do I transpose a matrix in GAMS?
aileen
User
User
Posts: 136
Joined: 4 years ago

Re: How do I transpose a matrix?

Post by aileen »

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

Code: Select all

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:

Code: Select all

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