<?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: How to calculate difference between two vectors in a matrix format in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-calculate-difference-between-two-vectors-in-a-matrix/m-p/81889#M486</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The repeat function is one way of doing this.&amp;nbsp; For example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc iml;&lt;/P&gt;&lt;P&gt;&amp;nbsp; vr = {10 15};&lt;/P&gt;&lt;P&gt;&amp;nbsp; vc = {5, 10};&lt;/P&gt;&lt;P&gt;&amp;nbsp; m=repeat(vr,2,1)-repeat(vc,1,2);&lt;/P&gt;&lt;P&gt;&amp;nbsp; print m;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where 2 is the length of both vectors.&amp;nbsp; Note that in your example vc is not a column vector, so I have added a comma above.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope that helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 02 Aug 2012 07:10:23 GMT</pubDate>
    <dc:creator>IanWakeling</dc:creator>
    <dc:date>2012-08-02T07:10:23Z</dc:date>
    <item>
      <title>How to calculate difference between two vectors in a matrix format</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-calculate-difference-between-two-vectors-in-a-matrix/m-p/81888#M485</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to calculate the difference between a row vectror and a column vector in a matrix. For example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;vr = {10 15}&lt;/P&gt;&lt;P&gt;vc = {5 10}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;m = {5 10,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0 5}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;m = is the difference between them. m[1.1] = vr[1] - vc[1], m[1,2] = vr[2] - vc[1] etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Currently I am doing this using a loop. Is there a way to accomplish this using vector/matrix notation?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Eyal&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Aug 2012 03:53:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-calculate-difference-between-two-vectors-in-a-matrix/m-p/81888#M485</guid>
      <dc:creator>EyalGonen</dc:creator>
      <dc:date>2012-08-02T03:53:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate difference between two vectors in a matrix format</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-calculate-difference-between-two-vectors-in-a-matrix/m-p/81889#M486</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The repeat function is one way of doing this.&amp;nbsp; For example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc iml;&lt;/P&gt;&lt;P&gt;&amp;nbsp; vr = {10 15};&lt;/P&gt;&lt;P&gt;&amp;nbsp; vc = {5, 10};&lt;/P&gt;&lt;P&gt;&amp;nbsp; m=repeat(vr,2,1)-repeat(vc,1,2);&lt;/P&gt;&lt;P&gt;&amp;nbsp; print m;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where 2 is the length of both vectors.&amp;nbsp; Note that in your example vc is not a column vector, so I have added a comma above.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope that helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Aug 2012 07:10:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-calculate-difference-between-two-vectors-in-a-matrix/m-p/81889#M486</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2012-08-02T07:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate difference between two vectors in a matrix format</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-calculate-difference-between-two-vectors-in-a-matrix/m-p/81890#M487</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ian has the right idea, although you only need to use the REPEAT function once:&lt;/P&gt;&lt;P&gt;vr = {10 15};&lt;BR /&gt;vc = {5 10};&lt;/P&gt;&lt;P&gt;v = repeat(vr, ncol(vc)); /* repeat vector to create matrix */&lt;BR /&gt;m = v - vc`;&amp;nbsp; /* subtract i_th element from i_th row */&lt;BR /&gt;print m;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For details, see this article on "&lt;A href="http://blogs.sas.com/content/iml/2010/12/06/shorthand-notation-for-row-and-column-operations/"&gt;Shorthand notation for row and column operations&lt;/A&gt;."&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Aug 2012 10:48:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-calculate-difference-between-two-vectors-in-a-matrix/m-p/81890#M487</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2012-08-03T10:48:45Z</dc:date>
    </item>
  </channel>
</rss>

