Return the eigenvector corresponding to the max eigenvalue of A












0















As the title says, I must compute the eigenvector v corresponding to the max eigenvalue. I'm not sure what commands do this. Any tips?



import numpy as np
import scipy.linalg as la

#x and y both 1D NumPy arrays of same length
def eigen_X(x,y):
xa = np.mean(x)
ya = np.mean(y)
x_bar = x - xa
y_bar = y - ya
X = np.column_stack(x_bar,y_bar)
A = X.transpose()@X
#The rest of the code goes here









share|improve this question





























    0















    As the title says, I must compute the eigenvector v corresponding to the max eigenvalue. I'm not sure what commands do this. Any tips?



    import numpy as np
    import scipy.linalg as la

    #x and y both 1D NumPy arrays of same length
    def eigen_X(x,y):
    xa = np.mean(x)
    ya = np.mean(y)
    x_bar = x - xa
    y_bar = y - ya
    X = np.column_stack(x_bar,y_bar)
    A = X.transpose()@X
    #The rest of the code goes here









    share|improve this question



























      0












      0








      0








      As the title says, I must compute the eigenvector v corresponding to the max eigenvalue. I'm not sure what commands do this. Any tips?



      import numpy as np
      import scipy.linalg as la

      #x and y both 1D NumPy arrays of same length
      def eigen_X(x,y):
      xa = np.mean(x)
      ya = np.mean(y)
      x_bar = x - xa
      y_bar = y - ya
      X = np.column_stack(x_bar,y_bar)
      A = X.transpose()@X
      #The rest of the code goes here









      share|improve this question
















      As the title says, I must compute the eigenvector v corresponding to the max eigenvalue. I'm not sure what commands do this. Any tips?



      import numpy as np
      import scipy.linalg as la

      #x and y both 1D NumPy arrays of same length
      def eigen_X(x,y):
      xa = np.mean(x)
      ya = np.mean(y)
      x_bar = x - xa
      y_bar = y - ya
      X = np.column_stack(x_bar,y_bar)
      A = X.transpose()@X
      #The rest of the code goes here






      python eigenvalue eigenvector






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 19:29







      Chance Gordon

















      asked Nov 14 '18 at 19:06









      Chance GordonChance Gordon

      124




      124
























          2 Answers
          2






          active

          oldest

          votes


















          1














          scipy.linalg.eig provides a function that calculates eigenvalues and eigenvectors of a 2D, square matrix. To get the (right?) eigenvector corresponding to the largest eigenvalue, use



          w, vl, vr = la.eig(A)
          largest_eigenvector = vr[:, np.argmax(w)]


          Replace vr[:, np.argmax(w)] above with vl[np.argmax(w)] if you're looking for the corresponding left eigenvector.






          share|improve this answer































            0














            It's possible to do this with just numpy's "linalg" library. The eig() function can give you the eigenvalues and eigenvectors. I converted the eigenvalues from a numpy array into a list in order to use "index" here to find the position of the largest eigenvalue. Then I picked the corresponding column from the eigenvector array.



            >>> from numpy import linalg as LA
            >>> M = ((1,-3,3), (3,-5,3), (6,-6,4))
            >>> vals, vects = LA.eig(M)
            >>> maxcol = list(vals).index(max(vals))
            >>> eigenvect = vects[:,maxcol]
            >>> print eigenvect
            [-0.40824829+0.j -0.40824829+0.j -0.81649658+0.j]





            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53307152%2freturn-the-eigenvector-corresponding-to-the-max-eigenvalue-of-a%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              scipy.linalg.eig provides a function that calculates eigenvalues and eigenvectors of a 2D, square matrix. To get the (right?) eigenvector corresponding to the largest eigenvalue, use



              w, vl, vr = la.eig(A)
              largest_eigenvector = vr[:, np.argmax(w)]


              Replace vr[:, np.argmax(w)] above with vl[np.argmax(w)] if you're looking for the corresponding left eigenvector.






              share|improve this answer




























                1














                scipy.linalg.eig provides a function that calculates eigenvalues and eigenvectors of a 2D, square matrix. To get the (right?) eigenvector corresponding to the largest eigenvalue, use



                w, vl, vr = la.eig(A)
                largest_eigenvector = vr[:, np.argmax(w)]


                Replace vr[:, np.argmax(w)] above with vl[np.argmax(w)] if you're looking for the corresponding left eigenvector.






                share|improve this answer


























                  1












                  1








                  1







                  scipy.linalg.eig provides a function that calculates eigenvalues and eigenvectors of a 2D, square matrix. To get the (right?) eigenvector corresponding to the largest eigenvalue, use



                  w, vl, vr = la.eig(A)
                  largest_eigenvector = vr[:, np.argmax(w)]


                  Replace vr[:, np.argmax(w)] above with vl[np.argmax(w)] if you're looking for the corresponding left eigenvector.






                  share|improve this answer













                  scipy.linalg.eig provides a function that calculates eigenvalues and eigenvectors of a 2D, square matrix. To get the (right?) eigenvector corresponding to the largest eigenvalue, use



                  w, vl, vr = la.eig(A)
                  largest_eigenvector = vr[:, np.argmax(w)]


                  Replace vr[:, np.argmax(w)] above with vl[np.argmax(w)] if you're looking for the corresponding left eigenvector.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 14 '18 at 19:37









                  jwiljwil

                  1799




                  1799

























                      0














                      It's possible to do this with just numpy's "linalg" library. The eig() function can give you the eigenvalues and eigenvectors. I converted the eigenvalues from a numpy array into a list in order to use "index" here to find the position of the largest eigenvalue. Then I picked the corresponding column from the eigenvector array.



                      >>> from numpy import linalg as LA
                      >>> M = ((1,-3,3), (3,-5,3), (6,-6,4))
                      >>> vals, vects = LA.eig(M)
                      >>> maxcol = list(vals).index(max(vals))
                      >>> eigenvect = vects[:,maxcol]
                      >>> print eigenvect
                      [-0.40824829+0.j -0.40824829+0.j -0.81649658+0.j]





                      share|improve this answer




























                        0














                        It's possible to do this with just numpy's "linalg" library. The eig() function can give you the eigenvalues and eigenvectors. I converted the eigenvalues from a numpy array into a list in order to use "index" here to find the position of the largest eigenvalue. Then I picked the corresponding column from the eigenvector array.



                        >>> from numpy import linalg as LA
                        >>> M = ((1,-3,3), (3,-5,3), (6,-6,4))
                        >>> vals, vects = LA.eig(M)
                        >>> maxcol = list(vals).index(max(vals))
                        >>> eigenvect = vects[:,maxcol]
                        >>> print eigenvect
                        [-0.40824829+0.j -0.40824829+0.j -0.81649658+0.j]





                        share|improve this answer


























                          0












                          0








                          0







                          It's possible to do this with just numpy's "linalg" library. The eig() function can give you the eigenvalues and eigenvectors. I converted the eigenvalues from a numpy array into a list in order to use "index" here to find the position of the largest eigenvalue. Then I picked the corresponding column from the eigenvector array.



                          >>> from numpy import linalg as LA
                          >>> M = ((1,-3,3), (3,-5,3), (6,-6,4))
                          >>> vals, vects = LA.eig(M)
                          >>> maxcol = list(vals).index(max(vals))
                          >>> eigenvect = vects[:,maxcol]
                          >>> print eigenvect
                          [-0.40824829+0.j -0.40824829+0.j -0.81649658+0.j]





                          share|improve this answer













                          It's possible to do this with just numpy's "linalg" library. The eig() function can give you the eigenvalues and eigenvectors. I converted the eigenvalues from a numpy array into a list in order to use "index" here to find the position of the largest eigenvalue. Then I picked the corresponding column from the eigenvector array.



                          >>> from numpy import linalg as LA
                          >>> M = ((1,-3,3), (3,-5,3), (6,-6,4))
                          >>> vals, vects = LA.eig(M)
                          >>> maxcol = list(vals).index(max(vals))
                          >>> eigenvect = vects[:,maxcol]
                          >>> print eigenvect
                          [-0.40824829+0.j -0.40824829+0.j -0.81649658+0.j]






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 14 '18 at 19:44









                          Bill M.Bill M.

                          835112




                          835112






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53307152%2freturn-the-eigenvector-corresponding-to-the-max-eigenvalue-of-a%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Bressuire

                              Vorschmack

                              Quarantine