<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Reshaping a matrix in a particular way in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-a-matrix-in-a-particular-way/m-p/503680#M4391</link>
    <description>&lt;P&gt;Perfect! Thank you very much!&lt;/P&gt;</description>
    <pubDate>Fri, 12 Oct 2018 11:05:25 GMT</pubDate>
    <dc:creator>Alain38</dc:creator>
    <dc:date>2018-10-12T11:05:25Z</dc:date>
    <item>
      <title>Reshaping a matrix in a particular way</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-a-matrix-in-a-particular-way/m-p/503671#M4388</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;I would like to reshape the matrix A :&lt;BR /&gt;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp; 3&lt;BR /&gt;&amp;nbsp;&amp;nbsp; 4 &amp;nbsp; 5&amp;nbsp;&amp;nbsp; 6&lt;BR /&gt;&amp;nbsp;&amp;nbsp; 7&amp;nbsp;&amp;nbsp; 8 &amp;nbsp; 9&lt;BR /&gt;&amp;nbsp;10 11 12&lt;BR /&gt;&amp;nbsp;13 14 15&lt;BR /&gt;&amp;nbsp;16 17 18&lt;BR /&gt;&amp;nbsp;19 20 21&lt;BR /&gt;&amp;nbsp;22 23 24&lt;BR /&gt;&lt;BR /&gt;which is (8*3) into the following matrix (4*6):&lt;BR /&gt;&amp;nbsp; 1&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp; 3 13 14 15&lt;BR /&gt;&amp;nbsp; 4&amp;nbsp;&amp;nbsp; 5&amp;nbsp;&amp;nbsp; 6 16 17 18&lt;BR /&gt;&amp;nbsp; 7&amp;nbsp;&amp;nbsp; 8&amp;nbsp;&amp;nbsp; 9 19 20 21&lt;BR /&gt;10 11 12 22 23 24&lt;BR /&gt;&lt;BR /&gt;In the following code, test2 delivers this for this simplified example, but it does not suit when the actual matrix is for example (9000*3) and has to be reshaped in (450*60), i.e each of the 20 blocks of (450*3) moves on the right, one after another. So I would prefer a code more general like test1, but the shape function - in this form at least - does not deliver the result I want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc IML;
	A = {1 2 3, 4 5 6, 7 8 9, 10 11 12, 13 14 15, 16 17 18, 19 20 21, 22 23 24};
	test1 = shape(A, 4, 6);
	test2 = A[1:4,] || A[5:8,];
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you for your help,&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 10:29:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-a-matrix-in-a-particular-way/m-p/503671#M4388</guid>
      <dc:creator>Alain38</dc:creator>
      <dc:date>2018-10-12T10:29:12Z</dc:date>
    </item>
    <item>
      <title>Re: Reshaping a matrix in a particular way</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-a-matrix-in-a-particular-way/m-p/503674#M4389</link>
      <description>&lt;P&gt;If the original matrix is&amp;nbsp;N x 3, it is not clear to me how you are forming the final matrix in terms of N. For example, in the 9000 x 3 example, what are the rules for getting the 450 x 60 matrix? You mention "blocks of 20", so I thought you were looking for a 20 x 1350 matrix as the output.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If N is the number of rows in the original matrix and p is the number of columns (is p always 3???) and k is the "block size", can you describe how&amp;nbsp;to get the new matrix from the old?&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 10:42:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-a-matrix-in-a-particular-way/m-p/503674#M4389</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-10-12T10:42:13Z</dc:date>
    </item>
    <item>
      <title>Re: Reshaping a matrix in a particular way</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-a-matrix-in-a-particular-way/m-p/503679#M4390</link>
      <description>&lt;P&gt;I think this might do&amp;nbsp;what you want, where all you need to do is pre-specify the number of blocks required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;

x = shape(1:36,12,3);
print x;

nblocks = 3;
cidx = shape(1:ncol(x)#nblocks, ncol(x), nblocks);
y = shapecol(x, nrow(x)/nblocks)[ ,t(cidx)];
print y;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Oct 2018 10:55:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-a-matrix-in-a-particular-way/m-p/503679#M4390</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2018-10-12T10:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: Reshaping a matrix in a particular way</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-a-matrix-in-a-particular-way/m-p/503680#M4391</link>
      <description>&lt;P&gt;Perfect! Thank you very much!&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 11:05:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-a-matrix-in-a-particular-way/m-p/503680#M4391</guid>
      <dc:creator>Alain38</dc:creator>
      <dc:date>2018-10-12T11:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: Reshaping a matrix in a particular way</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-a-matrix-in-a-particular-way/m-p/503683#M4392</link>
      <description>&lt;P&gt;Oh, I see now. After studying the question and Ian's solution, it appears that the OP is asking for a block transpose. You can use&lt;A href="https://go.documentation.sas.com/?docsetId=imlug&amp;amp;docsetTarget=imlug_langref_sect071.htm&amp;amp;docsetVersion=14.3&amp;amp;locale=en" target="_self"&gt; the BTRAN function&lt;/A&gt; in SAS/IML to compute a block transpose. It is not clear whether the OP wants to specify the blocksize or the number of blocks. Both options are shown below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
x = shape(1:36,12,3);
blocksize = 4;
y = btran(x, blocksize, ncol(x));
print y;

x = shape(1:9000*3,0,3);     /* 9000 x 3 matrix */
nblocks = 20;
blocksize = nrow(x) / nblocks;
y = btran(x, blocksize, ncol(x));
print (dimension(y))[c={"nrow" "ncol"}];
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Oct 2018 12:03:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-a-matrix-in-a-particular-way/m-p/503683#M4392</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-10-12T12:03:48Z</dc:date>
    </item>
    <item>
      <title>Re: Reshaping a matrix in a particular way</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-a-matrix-in-a-particular-way/m-p/503687#M4393</link>
      <description>&lt;P&gt;Works well too! Thank you very much!&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 12:16:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-a-matrix-in-a-particular-way/m-p/503687#M4393</guid>
      <dc:creator>Alain38</dc:creator>
      <dc:date>2018-10-12T12:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: Reshaping a matrix in a particular way</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-a-matrix-in-a-particular-way/m-p/503691#M4394</link>
      <description>&lt;P&gt;Oh!&amp;nbsp;I did it the hard way, because I didn't know that BTRAN existed.&amp;nbsp;&amp;nbsp;Perhaps you should blog about it Rick, to try and get it more widely known?&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 12:23:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-a-matrix-in-a-particular-way/m-p/503691#M4394</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2018-10-12T12:23:22Z</dc:date>
    </item>
  </channel>
</rss>

