code: def _calculateApicalSegmentActivity(connections, activeInput, connectedPermanence,
                                  activationThreshold, minThreshold):
      
  
      # Active
      overlaps = connections.computeActivity(activeInput, connectedPermanence)
      activeSegments = np.flatnonzero(overlaps >= activationThreshold)
  
      # Matching
      potentialOverlaps = connections.computeActivity(activeInput)
      matchingSegments = np.flatnonzero(potentialOverlaps >= minThreshold)
  
      return (activeSegments,
              matchingSegments,
              potentialOverlaps)
docs: Calculate the active and matching apical segments for this timestep.
  
      @param connections (SparseMatrixConnections)
      @param activeInput (numpy array)
  
      @return (tuple)
      - activeSegments (numpy array)
        Dendrite segments with enough active connected synapses to cause a
        dendritic spike
  
      - matchingSegments (numpy array)
        Dendrite segments with enough active potential synapses to be selected for
        learning in a bursting column
  
      - potentialOverlaps (numpy array)
        The number of active potential synapses for each segment.
        Includes counts for active, matching, and nonmatching segments.