class_docstr: Encodes list/array format piece into pianorolls and decodes into midi.
docstr: Encode sequence into pianoroll.
docstr_tok: ["Encode","sequence","into","pianoroll","."]
code: 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))
  
file_path: magenta/magenta/models/coconet/lib_pianoroll.py
imports: import numpy
  import pretty_midi
  import tensorflow.compat.v1
label_desc: Use image node_id 2 for calling the PianorollEncoderDecoder obj's underlying member method code with example usage: obj.encode(sequence) and returns: self