class_docstr: Samples random dimensions from the target at training time.
class_docstr_tok: ["Samples","random","dimensions","from","the","target","at","training","time","."]
code: def flatmap_transform(
      self, data: DataEntry, is_train: bool
  ) -> Iterator[DataEntry]:
      if not is_train:
          yield data
      else:
          # (target_dim,)
          target_dimensions = data[self.field_name]
  
          if self.shuffle:
              np.random.shuffle(target_dimensions)
  
          target_dimensions = target_dimensions[: self.num_samples]
  
          data[self.field_name] = target_dimensions
          # (seq_len, target_dim) -> (seq_len, num_samples)
  
          for field in [
              f"past_{self.target_field}",
              f"future_{self.target_field}",
              f"past_{self.observed_values_field}",
              f"future_{self.observed_values_field}",
          ]:
              data[field] = data[field][:, target_dimensions]
  
          yield data
  
imports: from typing import Callable, Iterator, List, Optional, Tuple, Type
  import numpy
  from toolz import valmap
  from gluonts.core.component import validated, tensor_to_numpy
  from gluonts.dataset.common import DataEntry
  from gluonts.exceptions import assert_data_error
  from ._base import FlatMapTransformation, MapTransformation, SimpleTransformation
label_desc: Use image node_id 2 for calling the SampleTargetDim obj's underlying member method code with example usage: obj.flatmap_transform(data, is_train) without return types