code: def _learn(connections, rng, learningSegments, activeInput,
               potentialOverlaps, initialPermanence, sampleSize,
               permanenceIncrement, permanenceDecrement, maxSynapsesPerSegment):
      
      # Learn on existing segments
      connections.adjustSynapses(learningSegments, activeInput,
                                 permanenceIncrement, -permanenceDecrement)
  
      # Grow new synapses. Calculate "maxNew", the maximum number of synapses to
      # grow per segment. "maxNew" might be a number or it might be a list of
      # numbers.
      if sampleSize == -1:
        maxNew = len(activeInput)
      else:
        maxNew = sampleSize - potentialOverlaps[learningSegments]
  
      if maxSynapsesPerSegment != -1:
        synapseCounts = connections.mapSegmentsToSynapseCounts(
          learningSegments)
        numSynapsesToReachMax = maxSynapsesPerSegment - synapseCounts
        maxNew = np.where(maxNew <= numSynapsesToReachMax,
                          maxNew, numSynapsesToReachMax)
  
      connections.growSynapsesToSample(learningSegments, activeInput,
                                       maxNew, initialPermanence, rng)
docs: Adjust synapse permanences, grow new synapses, and grow new segments.
  
      @param learningActiveSegments (numpy array)
      @param learningMatchingSegments (numpy array)
      @param segmentsToPunish (numpy array)
      @param activeInput (numpy array)
      @param potentialOverlaps (numpy array)