<?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: SAS to Python_eigenvalues in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/SAS-to-Python-eigenvalues/m-p/921519#M6180</link>
    <description>I need to use these results in another step, in which case the results obtained in SAS will be different from those obtained in Python, except that I absolutely must find the same results in SAS as in Python.</description>
    <pubDate>Fri, 22 Mar 2024 15:15:39 GMT</pubDate>
    <dc:creator>RO_C</dc:creator>
    <dc:date>2024-03-22T15:15:39Z</dc:date>
    <item>
      <title>SAS to Python_eigenvalues</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/SAS-to-Python-eigenvalues/m-p/921465#M6177</link>
      <description>&lt;P&gt;I'm converting SAS code into Python and I've noticed a difference between the results of a SAS procedure and its Python equivalent.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example :&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The SAS code :&lt;BR /&gt;proc iml;&lt;BR /&gt;abc = {1 2 3 1,&lt;BR /&gt;4 5 6 1,&lt;BR /&gt;7 8 9 1,&lt;BR /&gt;1 1 1 1};&lt;/P&gt;&lt;P&gt;/* Calculation of eigenvalues (eigm) and eigenvectors (eigv) */&lt;BR /&gt;eigm = eigval(abc);&lt;BR /&gt;eigv = eigvec(abc);&lt;BR /&gt;print eigm, eigv;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;the result :&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="image (1).png" style="width: 200px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94871iC6A60F55A75F91C6/image-size/small?v=v2&amp;amp;px=200" role="button" title="image (1).png" alt="image (1).png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Python equivalent of this SAS code :&lt;/P&gt;&lt;P&gt;import numpy as np&lt;/P&gt;&lt;P&gt;# Definition of matrix abc&lt;BR /&gt;abc = np.array([[1, 2, 3, 1],&lt;BR /&gt;[4, 5, 6, 1],&lt;BR /&gt;[7, 8, 9, 1],&lt;BR /&gt;[1, 1, 1, 1]])&lt;/P&gt;&lt;P&gt;# Calculation of eigenvalues and eigenvectors&lt;BR /&gt;eigenvalues, eigenvectors = np.linalg.eig(abc)&lt;/P&gt;&lt;P&gt;print("Eigenvalues :", eigenvalues)&lt;BR /&gt;print("Eigenvectors :\n", eigenvectors)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="unnamed1.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94870iF461DBDFC39B2690/image-size/medium?v=v2&amp;amp;px=400" role="button" title="unnamed1.png" alt="unnamed1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Remarks:&lt;BR /&gt;It's easy to see that the values are the same in both sets of results, but they don't follow the same layout.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2024 08:56:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/SAS-to-Python-eigenvalues/m-p/921465#M6177</guid>
      <dc:creator>RO_C</dc:creator>
      <dc:date>2024-03-22T08:56:51Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to Python_eigenvalues</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/SAS-to-Python-eigenvalues/m-p/921510#M6178</link>
      <description>&lt;P&gt;If&amp;nbsp; layout is an issue then send one or more sets of results to a data set and then write code to show in the desired layout (and rounded/formatted for similarity if desired).&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2024 13:56:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/SAS-to-Python-eigenvalues/m-p/921510#M6178</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-03-22T13:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to Python_eigenvalues</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/SAS-to-Python-eigenvalues/m-p/921513#M6179</link>
      <description>&lt;P&gt;So it's just an issue of the ordering of the eigenvector columns, right?&amp;nbsp; The SAS docs explain the SAS ordering:&lt;BR /&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.3/imlug/imlug_langref_sect123.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.3/imlug/imlug_langref_sect123.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The numpy docs explain that eigenvalues (and thus eigenvectors) are "not necessarily ordered."&lt;/P&gt;
&lt;P&gt;&lt;A href="https://numpy.org/doc/stable/reference/generated/numpy.linalg.eig.html" target="_blank"&gt;https://numpy.org/doc/stable/reference/generated/numpy.linalg.eig.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2024 14:49:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/SAS-to-Python-eigenvalues/m-p/921513#M6179</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-03-22T14:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to Python_eigenvalues</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/SAS-to-Python-eigenvalues/m-p/921519#M6180</link>
      <description>I need to use these results in another step, in which case the results obtained in SAS will be different from those obtained in Python, except that I absolutely must find the same results in SAS as in Python.</description>
      <pubDate>Fri, 22 Mar 2024 15:15:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/SAS-to-Python-eigenvalues/m-p/921519#M6180</guid>
      <dc:creator>RO_C</dc:creator>
      <dc:date>2024-03-22T15:15:39Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to Python_eigenvalues</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/SAS-to-Python-eigenvalues/m-p/921520#M6181</link>
      <description>In fact, the matrix I have is much larger than this one. I don't know what movements there will be in the other columns</description>
      <pubDate>Fri, 22 Mar 2024 15:18:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/SAS-to-Python-eigenvalues/m-p/921520#M6181</guid>
      <dc:creator>RO_C</dc:creator>
      <dc:date>2024-03-22T15:18:02Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to Python_eigenvalues</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/SAS-to-Python-eigenvalues/m-p/921521#M6182</link>
      <description>&lt;P&gt;I've moved this post to the IML board, which more closely aligns with this question. As pointed out by a previous answer, from the IML documentation, the eigenvalues for a non-symmetric matrix &lt;SPAN&gt;are sorted first by their real parts, then by the magnitude of their imaginary parts. You can get sorted eigenvalues from numpy using the numpy.linalg.eigh() function, but note that that function sorts eigenvalues in ascending order.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2024 15:18:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/SAS-to-Python-eigenvalues/m-p/921521#M6182</guid>
      <dc:creator>Mike_N</dc:creator>
      <dc:date>2024-03-22T15:18:30Z</dc:date>
    </item>
  </channel>
</rss>

