8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5da40c3 commit a908a34Copy full SHA for a908a34
useful_scripts/principal_eigenvector.py
@@ -0,0 +1,20 @@
1
+# Select a principal eigenvector via NumPy
2
+# to be used as a template (copy & paste) script
3
+
4
+import numpy as np
5
6
+# set A to be your matrix
7
+A = np.array([[1, 2, 3],
8
+ [4, 5, 6],
9
+ [7, 8, 9]])
10
11
12
+eig_vals, eig_vecs = np.linalg.eig(A)
13
+idx = np.absolute(eig_vals).argsort()[::-1] # decreasing order
14
+sorted_eig_vals = eig_vals[idx]
15
+sorted_eig_vecs = eig_vecs[:, idx]
16
17
+principal_eig_vec = sorted_eig_vecs[:, 0] # eigvec with largest eigval
18
19
+normalized_pr_eig_vec = np.real(principal_eig_vec / np.sum(principal_eig_vec))
20
+print(normalized_pr_eig_vec) # eigvec that sums up to one
0 commit comments