-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
29 lines (23 loc) · 759 Bytes
/
utils.py
File metadata and controls
29 lines (23 loc) · 759 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
import numpy as np
def reg_lens(state_arr):
sa=np.asarray(state_arr)
n=len(sa)
if n==0:
return (None,None)
else:
#we create a truth array for if a state is about to change:
x=np.array(sa[1:]!=sa[:-1])
#we create an array containing those entries of sa where x is true
#and append the final entry:
y=np.append(np.where(x),n-1)
#we create an array of persistent state lengths:
L=np.diff(np.append(-1,y))
#and an array of those state values:
S=sa[y]
return (L,S)
def persistent_state(ix,state,min_pers):
L,S=reg_lens(ix)
keepS=S==state
keepL=L>min_pers
keep_points=(np.repeat(keepL,L)*np.repeat(keepS,L))
return keep_points