code: def encode(self, data, flatten=False):
      
      if not isinstance(data, np.ndarray):
        data = np.array(data)
  
      # flatten if necessary
      if flatten:
        try:
          data = np.reshape(data, (self.filterDim, data.shape[-1]))
        except ValueError:
          # only one data point
          data = np.reshape(data, (self.filterDim, 1))
  
      if data.shape[0] != self.filterDim:
        raise ValueError("Data does not have the correct dimension!")
  
      # if single data point, convert to 2-dimensional array for consistency
      if len(data.shape) == 1:
        data = data[:, np.newaxis]
  
  
      projection = self.basis.T.dot(data)
      representation = self.basis.T.dot(self.basis) - np.eye(self.outputDim)
      states = np.zeros((self.outputDim, data.shape[1]))
  
      threshold = 0.5 * np.max(np.abs(projection), axis=0)
      activations = self._thresholdNonLinearity(states, threshold)
  
      for _ in xrange(self.numLcaIterations):
        # update dynamic system
        states *= (1 - self.lcaLearningRate)
        states += self.lcaLearningRate * (projection - representation.dot(activations))
        activations = self._thresholdNonLinearity(states, threshold)
  
        # decay threshold
        threshold *= self.thresholdDecay
        threshold[threshold < self.minThreshold] = self.minThreshold
  
      return activations
docs: Encodes the provided input data, returning a sparse vector of activations.
  
      It solves a dynamic system to find optimal activations, as proposed by
      Rozell et al. (2008).
      :param data:          (array) Data to be encoded (single point or multiple)
      :param flatten        (bool)  Whether or not the data needs to be flattened,
                                    in the case of images for example. Does not
                                    need to be enabled during training.
      :return:              (array) Array of sparse activations (dimOutput,
                                    numPoints)