-
Notifications
You must be signed in to change notification settings - Fork 6
/
functions.py
96 lines (84 loc) · 2.57 KB
/
functions.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import numpy as np
def nearest_points(row, col, ax, dg, size = (30,30)):
# row & col: Neuron corrdinates on which we plane to make connections
# ax: The number of elements to find along the horizontal and vertical axes.
# dg: The number of elements to find along the diagonal axes.
# size: The size of the 2D array (both rows and columns).
points = []
# Left
if ax > 0:
temp_row = row
temp_col = col - 1
while temp_col >= 0:
points.append((temp_row, temp_col))
if (col - temp_col) == ax:
break
temp_col -= 1
# Right
if ax > 0:
temp_row = row
temp_col = col + 1
while temp_col <= size[1]-1:
points.append((temp_row, temp_col))
if (temp_col - col) == ax:
break
temp_col += 1
# Top
if ax > 0:
temp_row = row - 1
temp_col = col
while temp_row >= 0:
points.append((temp_row, temp_col))
if (row - temp_row) == ax:
break
temp_row -= 1
# Bottom
if ax > 0:
temp_row = row + 1
temp_col = col
while temp_row <= size[0]-1:
points.append((temp_row, temp_col))
if (temp_row - row) == ax:
break
temp_row += 1
# Top-left diagonal
if dg > 0:
temp_row = row - 1
temp_col = col - 1
while temp_row >= 0 and temp_col >= 0:
points.append((temp_row, temp_col))
if (row - temp_row) == dg:
break
temp_row -= 1
temp_col -= 1
# Top-right diagonal
if dg > 0:
temp_row = row - 1
temp_col = col + 1
while temp_row >= 0 and temp_col <= size[1]-1:
points.append((temp_row, temp_col))
if (row - temp_row) == dg:
break
temp_row -= 1
temp_col += 1
# Bottom-left diagonal
if dg > 0:
temp_row = row + 1
temp_col = col - 1
while temp_row <= size[0]-1 and temp_col >= 0:
points.append((temp_row, temp_col))
if (temp_row - row) == dg:
break
temp_row += 1
temp_col -= 1
# Bottom-right diagonal
if dg > 0:
temp_row = row + 1
temp_col = col + 1
while temp_row <= size[0]-1 and temp_col <= size[1]-1:
points.append((temp_row, temp_col))
if (temp_row - row) == dg:
break
temp_row += 1
temp_col += 1
return points