def _fillInOnTimes(vector, durations):
 nonzeros = numpy.array(vector).nonzero()[0]
 if (len(nonzeros) == 0):
  return
 if (len(nonzeros) == 1):
  durations[nonzeros[0]] = 1
  return
 prev = nonzeros[0]
 onTime = 1
 onStartIdx = prev
 endIdx = nonzeros[(-1)]
 for idx in nonzeros[1:]:
  if (idx != (prev + 1)):
   durations[onStartIdx:(onStartIdx + onTime)] = range(1, (onTime + 1))
   onTime = 1
   onStartIdx = idx
  else:
   onTime += 1
  prev = idx
 durations[onStartIdx:(onStartIdx + onTime)] = range(1, (onTime + 1))

def _fillInOnTimes ( vector , durations ) : nonzeros = numpy . array ( vector ) . nonzero ( ) [ 0 ] if ( len ( nonzeros ) == 0 ) : return if ( len ( nonzeros ) == 1 ) : durations [ nonzeros [ 0 ] ] = 1 return prev = nonzeros [ 0 ] onTime = 1 onStartIdx = prev endIdx = nonzeros [ ( - 1 ) ] for idx in nonzeros [ 1 : ] : if ( idx != ( prev + 1 ) ) : durations [ onStartIdx : ( onStartIdx + onTime ) ] = range ( 1 , ( onTime + 1 ) ) onTime = 1 onStartIdx = idx else : onTime += 1 prev = idx durations [ onStartIdx : ( onStartIdx + onTime ) ] = range ( 1 , ( onTime + 1 ) )
helper function used by averageontimepertimestep .