(self, sequence)
Encode sequence into pianoroll.
Encode sequence into pianoroll.
Encode sequence into pianoroll .
def encode(self, sequence):
    """Encode sequence into pianoroll."""
    # Sequence can either be a 2D numpy array or a list of lists.
    if (isinstance(sequence, np.ndarray) and sequence.ndim == 2) or (
        isinstance(sequence, list) and
        isinstance(sequence[0], (list, tuple))):
      # If sequence is an numpy array should have shape (time, num_instruments).
      if (isinstance(sequence, np.ndarray) and
          sequence.shape[-1] != self.num_instruments):
        raise ValueError('Last dim of sequence should equal num_instruments.')
      if isinstance(sequence, np.ndarray) and not self.separate_instruments:
        raise ValueError('Only use numpy array if instruments are separated.')
      sequence = list(sequence)
      return self.encode_list_of_lists(sequence)
    else:
      raise TypeError('Type %s not yet supported.' % type(sequence))
def encode ( self , sequence ) : # Sequence can either be a 2D numpy array or a list of lists. if ( isinstance ( sequence , np . ndarray ) and sequence . ndim == 2 ) or ( isinstance ( sequence , list ) and isinstance ( sequence [ 0 ] , ( list , tuple ) ) ) : # If sequence is an numpy array should have shape (time, num_instruments). if ( isinstance ( sequence , np . ndarray ) and sequence . shape [ - 1 ] != self . num_instruments ) : raise ValueError ( 'Last dim of sequence should equal num_instruments.' ) if isinstance ( sequence , np . ndarray ) and not self . separate_instruments : raise ValueError ( 'Only use numpy array if instruments are separated.' ) sequence = list ( sequence ) return self . encode_list_of_lists ( sequence ) else : raise TypeError ( 'Type %s not yet supported.' % type ( sequence ) )