-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrayManipulation.py
85 lines (66 loc) · 1.72 KB
/
arrayManipulation.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
"""
This module was created, because Numpy takes after cx_freeze over 100 MB.
"""
def ones(const, numberOfRows, numberOfColumns):
a = [[const]*numberOfColumns for iR in range(numberOfRows)]
return(a)
def vstack(args):
# check for second dimension equality
numberOfColumns = list()
for arg in args:
secondDim = [len(arg[iR]) for iR in range(len(arg))]
numberOfColumns.extend(secondDim)
uniqNumberOfColumns = set(numberOfColumns)
if len(uniqNumberOfColumns)!=1:
raise Exception('Non-consistent number of columns.')
a = list()
for arg in args:
a.extend(arg)
return(a)
def hstack(args):
# check for first dimension equality
numberOfRows = [len(arg) for arg in args]
uniqNumberOfRows = set(numberOfRows)
if len(uniqNumberOfRows)!=1:
raise Exception('Non-consistent number of rows.')
uniqNumberOfRows = list(uniqNumberOfRows)[0]
a = list()
for iR in range(uniqNumberOfRows):
row = list()
for arg in args:
row.extend(arg[iR])
a.append(row)
return(a)
def repeat(what, howManyTimes, axis):
if axis==0:
numberOfRows = howManyTimes
numberOfColumns = 1
elif axis==1:
numberOfRows = 1
numberOfColumns = howManyTimes
else:
raise Exception('Not allowed axis. Choose 0(rows) or 1(columns)')
a = [what*numberOfColumns for iR in range(numberOfRows)]
return(a)
def size(a, axis):
if axis==0:
return(len(a))
elif axis==1:
return(len(a[0]))
else:
raise Exception('Not allowed axis. Choose 0(rows) or 1(columns)')
if __name__ == '__main__':
a = ones(1, 5, 3)
b = ones(2, 2, 3)
c = vstack([a, b])
a = ones(1, 3, 5)
b = ones(2, 3, 2)
c = hstack([a, b])
a = [1, 2, 3]
c = repeat(a, 4, 0)
a = [1, 2, 3]
c = repeat(a, 4, 1)
a = ones(1, 3, 5)
c = size(a, 0)
c = size(a, 1)
debug = 1