forked from ismorphism/DeepECG
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils_ml.py
More file actions
28 lines (22 loc) · 922 Bytes
/
utils_ml.py
File metadata and controls
28 lines (22 loc) · 922 Bytes
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
import numpy as np
def duplicate_padding(x, length):
"""
padding the x not with zeros but the copy of the x.
:param: x: np.array or a list of np.array
more general, it should be a list of objects, which has length and can be concatenate.
:param: length: int
:return np.array
"""
x_new = np.zeros((len(x), length))
for i, xx in enumerate(x):
if len(xx) >= length:
x_new[i, :] = xx[0: length]
else:
xx_copy_section = xx[0: (length - len(xx))]
xx_replay = np.hstack((xx, xx_copy_section)) # np.concatenate()
# concatenate copied x to original x until its length meets the upper bound
while len(xx_replay) < length:
xx_copy_section = xx[0:(length - len(xx_replay))]
xx_replay = np.hstack((xx_replay, xx_copy_section))
x_new[i, :] = xx_replay
return x_new