Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import math as m
- C1 = np.array([[1, 1 / 7, 1 / 5],
- [7, 1, 3],
- [5, 1 / 3, 1]])
- C2 = np.array([[1, 5, 9],
- [1 / 5, 1, 4],
- [1 / 9, 1 / 4, 1]])
- C3 = np.array([[1, 4, 1 / 5],
- [1 / 4, 1, 1 / 9],
- [5, 1 / 3, 1]])
- C4 = np.array([[1, 9, 4],
- [1 / 9, 1, 1 / 4],
- [1 / 4, 4, 1]])
- C5 = np.array([[1, 1, 1],
- [1, 1, 1],
- [1, 1, 1]])
- C6 = np.array([[1, 6, 4],
- [1 / 6, 1, 1 / 3],
- [1 / 4, 3, 1]])
- C7 = np.array([[1, 9, 6],
- [1 / 9, 1, 1 / 3],
- [1 / 6, 3, 1]])
- C8 = np.array([[1, 1 / 2, 1 / 2],
- [2, 1, 1],
- [2, 1, 1]])
- list_C = [C1, C2, C3, C4, C5, C6, C7, C8]
- wektory_wlasne = []
- for c in list_C:
- w, v = np.linalg.eig(c)
- w1, w2, w3 = w
- v1, v2, v3 = v
- if not np.isreal(w1):
- w1 = -m.inf
- if not np.isreal(w2):
- w2 = -m.inf
- if not np.isreal(w3):
- w3 = -m.inf
- values = [np.real(w1), np.real(w2), np.real(w3)]
- i = values.index(max(values))
- wektory_wlasne.append(np.real(v[:, i]))
- for wektor in wektory_wlasne:
- suma = sum(wektor)
- wektor[0] = wektor[0] / suma
- wektor[1] = wektor[1] / suma
- wektor[2] = wektor[2] / suma
- Wec = np.transpose(np.array(wektory_wlasne))
- X = np.array([[1.0, 4.0, 7.0, 5.0, 8.0, 6.0, 6.0, 2.0],
- [1 / 4, 1.0, 5.0, 3.0, 7.0, 6.0, 6.0, 1 / 3],
- [1 / 7, 1 / 5, 1.0, 1 / 3, 5.0, 3.0, 3.0, 1 / 5],
- [1 / 5, 1 / 3, 3, 1, 6.0, 3.0, 4.0, 1 / 2],
- [1 / 8, 1 / 7, 1 / 5, 1 / 6, 1.0, 1 / 3, 1 / 4, 1 / 7],
- [1 / 6, 1 / 6, 1 / 3, 1 / 3, 3.0, 1.0, 1 / 2, 1 / 5],
- [1 / 6, 1 / 6, 1 / 3, 1 / 4, 4.0, 2.0, 1.0, 1 / 5],
- [1 / 2, 3.0, 5.0, 2.0, 7.0, 5.0, 5.0, 1.0]])
- result = Wec.dot(X)
- print('Result 1: ', sum(result[0]))
- print('Result 2: ', sum(result[1]))
- print('Result 3: ', sum(result[2]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement