GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — python_reference/useful_scripts/principal_eigenvector.py at master · l3ldon/python_reference

Expand file tree

/

principal_eigenvector.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
20 lines (14 loc) · 598 Bytes
/

principal_eigenvector.py

Copy path

File metadata and controls

20 lines (14 loc) · 598 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Select a principal eigenvector via NumPy
# to be used as a template (copy & paste) script
import numpy as np
# set A to be your matrix
A = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
eig_vals, eig_vecs = np.linalg.eig(A)
idx = np.absolute(eig_vals).argsort()[::-1] # decreasing order
sorted_eig_vals = eig_vals[idx]
sorted_eig_vecs = eig_vecs[:, idx]
principal_eig_vec = sorted_eig_vecs[:, 0] # eigvec with largest eigval
normalized_pr_eig_vec = np.real(principal_eig_vec / np.sum(principal_eig_vec))
print(normalized_pr_eig_vec) # eigvec that sums up to one
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.