<?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: One-Hot Vectors in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/One-Hot-Vectors/m-p/317996#M3119</link>
    <description>&lt;P&gt;The easiest way is to use &lt;A href="http://support.sas.com/documentation/cdl/en/imlug/68150/HTML/default/viewer.htm#imlug_langref_sect465.htm" target="_self"&gt;the SUB2NDX function&lt;/A&gt; to convert (row,col) subscripts into indices. &amp;nbsp;You didn't specify the dimensions of the final matrix, so in the following example I used a 10-column matrix. You can modify the dimension as you need to:&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
have = {6,9,1,2};
/* Somewhere you need to specify the columns of want? 
   Is it max(have)? Is is square? */
want = j(nrow(have),10,0);
rows = T(1:nrow(have));
idx = sub2ndx(dimension(want), rows||have);
want[idx] = 1;
print want;&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 09 Dec 2016 20:43:32 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2016-12-09T20:43:32Z</dc:date>
    <item>
      <title>One-Hot Vectors</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/One-Hot-Vectors/m-p/317992#M3118</link>
      <description>&lt;P&gt;I have an &lt;EM&gt;nx1&lt;/EM&gt; column vector, each element e_n an integer between 1 and p.&amp;nbsp; I want to convert it to an &lt;EM&gt;nxp&lt;/EM&gt; matrix with a 1 as&amp;nbsp;the e_nth element of each row and the rest 0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;have = {6,9,1,...}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;want = {0 0 0 0 0 1 0 0 0&amp;nbsp; ... ,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0 0 0 0 0 0 0 0 1 ... ,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 0 0 0 0 0 0 0 0 ... ,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What's the easiest way to do that?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2016 20:29:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/One-Hot-Vectors/m-p/317992#M3118</guid>
      <dc:creator>mcs</dc:creator>
      <dc:date>2016-12-09T20:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: One-Hot Vectors</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/One-Hot-Vectors/m-p/317996#M3119</link>
      <description>&lt;P&gt;The easiest way is to use &lt;A href="http://support.sas.com/documentation/cdl/en/imlug/68150/HTML/default/viewer.htm#imlug_langref_sect465.htm" target="_self"&gt;the SUB2NDX function&lt;/A&gt; to convert (row,col) subscripts into indices. &amp;nbsp;You didn't specify the dimensions of the final matrix, so in the following example I used a 10-column matrix. You can modify the dimension as you need to:&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
have = {6,9,1,2};
/* Somewhere you need to specify the columns of want? 
   Is it max(have)? Is is square? */
want = j(nrow(have),10,0);
rows = T(1:nrow(have));
idx = sub2ndx(dimension(want), rows||have);
want[idx] = 1;
print want;&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Dec 2016 20:43:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/One-Hot-Vectors/m-p/317996#M3119</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-12-09T20:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: One-Hot Vectors</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/One-Hot-Vectors/m-p/318072#M3121</link>
      <description>&lt;PRE&gt;
Or use this simple way to get index you need.


proc iml;
have = {6,9,1,2};
want = j(nrow(have),max(have),0);
idx = t(have)+(0:nrow(have)-1)#max(have);
want[idx] = 1;
print want; 
quit;

&lt;/PRE&gt;</description>
      <pubDate>Sat, 10 Dec 2016 11:16:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/One-Hot-Vectors/m-p/318072#M3121</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-12-10T11:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: One-Hot Vectors</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/One-Hot-Vectors/m-p/318225#M3125</link>
      <description>&lt;P&gt;Or how about the 'unique design' trick?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;

have = {6, 9, 1, 6, 2};

want = j( nrow(have), max(have), 0);
want[ , unique(have)] = design(have);

print want;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Dec 2016 08:48:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/One-Hot-Vectors/m-p/318225#M3125</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2016-12-12T08:48:15Z</dc:date>
    </item>
  </channel>
</rss>

