-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextra_functions.py
55 lines (37 loc) · 1.16 KB
/
extra_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
import schemdraw.elements as elm
from schemdraw.segments import *
def matrix_maker(num_rows, num_cols, value):
# alternative to numpy.zeros
# makes a matrix filled with specified value
matrix = []
for i in range(0, num_rows):
matrix.append([])
for j in range(0, num_cols):
matrix[i].append(value)
return matrix
def vector_maker(num_elems, value):
# makes a vector filled with specified value
vector = []
for i in range(0, num_elems):
vector.append(value)
return vector
def sum_lists(list_array):
# adds all lists in list_array together
output = vector_maker(len(list_array[0]), 0)
for list in list_array:
for i in range(0, len(list)):
output[i] += list[i]
return output
def sub_list(list1, list2):
return [list1[0]-list2[0], list1[1]-list2[1]]
def div_list(list1, n):
return [list1[0]/n, list1[1]/n]
def print_matrix(matrix):
for line in matrix:
print(line)
class Wire(elm.Element):
def __init__(self, path, color):
super().__init__()
line = Segment(path)
line.color = color
self.segments.append(line)