def encode_value(self, values):
    """Encodes a feature into its Example proto representation."""
    del self._value[:]
    if self._rank == 0:
      scalar_value = values if not isinstance(values,
                                              np.ndarray) else values.item()
      self._value.append(self._cast_fn(scalar_value))
    else:
      flattened_values = (
          values if self._rank == 1 else np.asarray(
              values, dtype=self._np_dtype).reshape(-1))
      if len(flattened_values) != self._size:
        raise ValueError('FixedLenFeature %r got wrong number of values. '
                         'Expected %d but got %d' %
                         (self._name, self._size, len(flattened_values)))
      self._value.extend(self._cast_fn(flattened_values))
Encodes a feature into its Example proto representation.
tensorflow_transform/coders/example_proto_coder.py