-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPython_Matrices.py
66 lines (49 loc) · 1.2 KB
/
Python_Matrices.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
import math
import random
import matplotlib.pyplot as plt
def Matrix(cols, rows):
mat = []
for _ in range(rows):
row = []
for _ in range(cols):
pixel = []
# val = random.randint(0, 1000) / 1000.0
for _ in range(3):
# pixel.append(val)
pixel.append(0)
row.append(pixel)
mat.append(row)
return mat
def diag(matrix, start=0, step=1):
rows = len(matrix)
cols = len(matrix[0])
i = start
for n in range(min(cols, rows)):
matrix[n][n] = []
for _ in range(3):
matrix[n][n].append(i)
i += step
def matrixMaximum(matrix):
rows = len(matrix)
cols = len(matrix[0])
maxVal = 0
for r in range(rows):
for c in range(cols):
maxVal = max(maxVal, matrix[r][c][0])
return maxVal
mat = Matrix(50, 50)
# print(mat)
# print("\n\n")
diag(mat, 1, 2)
# print(mat)
matMax = matrixMaximum(mat)
rows = len(mat)
cols = len(mat[0])
for r in range(rows):
for c in range(cols):
val = mat[r][c][0]
mat[r][c] = []
for _ in range(3):
mat[r][c].append(val / matMax)
plt.imshow(mat)
plt.show()