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

def _listOfOnTimesInVec ( vector ) : durations = [ ] numOnTimes = 0 totalOnTime = 0 nonzeros = numpy . array ( vector ) . nonzero ( ) [ 0 ] if ( len ( nonzeros ) == 0 ) : return ( 0 , 0 , [ ] ) if ( len ( nonzeros ) == 1 ) : return ( 1 , 1 , [ 1 ] ) prev = nonzeros [ 0 ] onTime = 1 endIdx = nonzeros [ ( - 1 ) ] for idx in nonzeros [ 1 : ] : if ( idx != ( prev + 1 ) ) : totalOnTime += onTime numOnTimes += 1 durations . append ( onTime ) onTime = 1 else : onTime += 1 prev = idx totalOnTime += onTime numOnTimes += 1 durations . append ( onTime ) return ( totalOnTime , numOnTimes , durations )
returns 3 things for a vector: * the total on time * the number of runs * a list of the durations of each run .