-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
56 lines (40 loc) · 1.28 KB
/
main.py
File metadata and controls
56 lines (40 loc) · 1.28 KB
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
# This is a sample Python script.
#BUILDING BLOCKS TO LENIA
import numpy as np
import matplotlib.pyplot as plt
# array_2d = np.array([
# [1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
# [1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
# [1, 1, 1, 0, 0, 0, 0, 0, 0, 0],
# [1, 1, 1, 1, 0, 0, 0, 0, 0, 0],
# [1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
# [1, 1, 1, 1, 1, 1, 0, 0, 0, 0],
# [1, 1, 1, 1, 1, 1, 1, 0, 0, 0],
# [1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
# [1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
# [1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
# ])
array_2d = np.random.random((100,100))
kernel = np.array([
[0.8, 0.8, 0.8],
[0.8, 0, 0.8],
[0.8, 0.8, 0.8]
])
result = np.zeros_like(array_2d)
for i in range(1, array_2d.shape[0] - 1):
for j in range(1, array_2d.shape[1] - 1):
if (i - 1 >= 1) and (i+2 <= array_2d.shape[0]):
if (j - 1 >= 1) and (j + 2 <= array_2d.shape[1]):
result[i][j] = np.sum(array_2d[i-1:i+2, j-1:j+2] * kernel)
plt.subplot(1, 3, 1)
plt.imshow(kernel, cmap='Grays')
plt.colorbar()
plt.subplot(1, 3, 2)
plt.imshow(array_2d, cmap='Grays')
plt.colorbar()
plt.subplot(1, 3, 3)
plt.imshow(result, cmap='Grays')
plt.colorbar()
plt.show()
if __name__ == '__main__':
print('hello')