-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrangen.py
More file actions
44 lines (30 loc) · 806 Bytes
/
rangen.py
File metadata and controls
44 lines (30 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import numpy as np
import math
import pandas as pd
import networkx as nx
import matplotlib.pyplot as plt
arr = pd.read_csv("image",delim_whitespace=True, header = None)
rows = 50
g = nx.Graph()
largest = {}
count = 0
for vec1 in range(1,rows):
v = arr.iloc[vec1,1:]
mag = math.sqrt(sum(i**2 for i in v))
v = v/mag
for vec2 in range(1,rows):
v2 = arr.iloc[vec2,1:]
mag2 = math.sqrt(sum(i**2 for i in v2))
v2 = v2/mag2
count +=1
if np.dot(v, v2) > 0.8 and np.dot(v,v2) != 1.0:
g.add_edge(arr.iloc[vec1,0],arr.iloc[vec2,0],weight=str(np.dot(v,v2)))
if arr.iloc[vec1,0] in largest:
largest[arr.iloc[vec1,0]] += 1
else:
largest[arr.iloc[vec1,0]] = 1
key, value = max(largest.iteritems(), key=lambda x:x[1])
print key,value
nx.draw(g)
plt.draw()
plt.show()