code: def in_scale_rate(pianoroll, key=3, kind='major'):
      
      if not isinstance(key, int):
          raise TypeError("`key` must an integer.")
      if key > 11 or key < 0:
          raise ValueError("`key` must be in an integer in between 0 and 11.")
      if kind not in ('major', 'minor'):
          raise ValueError("`kind` must be one of 'major' or 'minor'.")
      _validate_pianoroll(pianoroll)
  
      def _scale_mask(key, kind):
          """Return a scale mask for the given key. Default to C major scale."""
          if kind == 'major':
              a_scale_mask = np.array([0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1], bool)
          else:
              a_scale_mask = np.array([1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1], bool)
          return np.roll(a_scale_mask, key)
  
      chroma = _to_chroma(pianoroll)
      scale_mask = _scale_mask(key, kind)
      n_in_scale = np.sum(scale_mask.reshape(-1, 12) * chroma)
      return n_in_scale / np.count_nonzero(pianoroll)
docs: Return the ratio of the number of nonzero entries that lie in a specific
      scale to the total number of nonzero entries in a pianoroll. Default to C
      major scale.