-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnumpy.py
More file actions
77 lines (50 loc) · 1.35 KB
/
numpy.py
File metadata and controls
77 lines (50 loc) · 1.35 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import numpy as np
A = np.array(
[[1,2,3],
[4,5,6]]
)
# Transpose
AT = A.T
# Multiply two Matrices
# (2,3) * (3, 2) -> (2, 2)
A2 = A.dot(A.T)
A2 = A.dot(A, np.transpose(A))
np.transpose(A)
# tensors
A_zeros = np.zeros(shape= (2,3,2))
A_ones = np.ones(shape=(3,2,2))
B = np.arange(2, 49, 2)
B_t = B.reshape(2, 3, 4)
B_t.shape
B_t.ndim
from numpy import random as rnd
min_value = -1
max_value = 1
number_of_samples = 300
U = rnd.uniform(min_value, max_value, size=number_of_samples) # uniform samples in range (min_value, max_value)
f"Mean: {U.mean():.3f} Variance: {U.var():.2f} Std: {U.std():.2f}"
def simulate(node, T, flist):
if len(flist) > 1999:
return flist
else:
choice = random.choice(T[node])
flist = flist.append(choice)
simulate(choice,T, flist)
transition = {'A': 'BE', 'B': 'AFC',
'C': 'BGD',
'D': 'CH',
'E': 'AF',
'F': 'EBG',
'G': 'FCH',
'H': 'GD'}
# keys = np.fromiter(transition.keys(), dtype=np.float64)
# vals = np.fromiter(transition.values())
matrix = np.zeros((8,8))
keys = [*transition]
for key in keys:
for value in transition[key]:
row = keys.index(key) # 0
column = keys.index(value) # 1
matrix[row, column] = (1 / len(transition[key]))
# matrix[column, row] += (1 / 8)
x = np.linspace(-2,6,100)