forked from zcaicaros/L2D
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateEntTimeLB.py
More file actions
33 lines (25 loc) · 857 Bytes
/
Copy pathupdateEntTimeLB.py
File metadata and controls
33 lines (25 loc) · 857 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
29
30
31
32
33
import numpy as np
def lastNonZero(arr, axis, invalid_val=-1):
mask = arr != 0
val = arr.shape[axis] - np.flip(mask, axis=axis).argmax(axis=axis) - 1
yAxis = np.where(mask.any(axis=axis), val, invalid_val)
xAxis = np.arange(arr.shape[0], dtype=np.int64)
xRet = xAxis[yAxis >= 0]
yRet = yAxis[yAxis >= 0]
return xRet, yRet
def calEndTimeLB(temp1, dur_cp):
x, y = lastNonZero(temp1, 1, invalid_val=-1)
dur_cp[np.where(temp1 != 0)] = 0
dur_cp[x, y] = temp1[x, y]
temp2 = np.cumsum(dur_cp, axis=1)
temp2[np.where(temp1 != 0)] = 0
ret = temp1+temp2
return ret
if __name__ == '__main__':
dur = np.array([[1, 2], [3, 4]])
temp1 = np.zeros_like(dur)
temp1[0, 0] = 1
temp1[1, 0] = 3
temp1[1, 1] = 5
print(temp1)
ret = calEndTimeLB(temp1, dur)