def averageOnTime(vectors, numSamples=None):
 if (vectors.ndim == 1):
  vectors.shape = ((-1), 1)
 numTimeSteps = len(vectors)
 numElements = len(vectors[0])
 if (numSamples is None):
  numSamples = numElements
  countOn = range(numElements)
 else:
  countOn = numpy.random.randint(0, numElements, numSamples)
 sumOfLengths = 0.0
 onTimeFreqCounts = None
 n = 0
 for i in countOn:
  (onTime, segments, durations) = _listOfOnTimesInVec(vectors[:, i])
  if (onTime != 0.0):
   sumOfLengths += onTime
   n += segments
   onTimeFreqCounts = _accumulateFrequencyCounts(durations, onTimeFreqCounts)
 if (n > 0):
  return ((sumOfLengths / n), onTimeFreqCounts)
 else:
  return (0.0, onTimeFreqCounts)

def averageOnTime ( vectors , numSamples = None ) : if ( vectors . ndim == 1 ) : vectors . shape = ( ( - 1 ) , 1 ) numTimeSteps = len ( vectors ) numElements = len ( vectors [ 0 ] ) if ( numSamples is None ) : numSamples = numElements countOn = range ( numElements ) else : countOn = numpy . random . randint ( 0 , numElements , numSamples ) sumOfLengths = 0.0 onTimeFreqCounts = None n = 0 for i in countOn : ( onTime , segments , durations ) = _listOfOnTimesInVec ( vectors [ : , i ] ) if ( onTime != 0.0 ) : sumOfLengths += onTime n += segments onTimeFreqCounts = _accumulateFrequencyCounts ( durations , onTimeFreqCounts ) if ( n > 0 ) : return ( ( sumOfLengths / n ) , onTimeFreqCounts ) else : return ( 0.0 , onTimeFreqCounts )
returns the average on-time .