Shortcuts

IndexAdder

class torchdata.datapipes.iter.IndexAdder(source_datapipe: IterDataPipe[Dict], index_name: str = 'index')

Adds an index to an existing Iterable DataPipe with (functional name: add_index). The row or batch within the DataPipe must have the type Dict; otherwise, a NotImplementedError will be thrown. The index of the data is set to the provided index_name.

Parameters:
  • source_datapipe – Iterable DataPipe being indexed, its row/batch must be of type Dict

  • index_name – Name of the key to store data index

Example

>>> from torchdata.datapipes.iter import IterableWrapper
>>> dp = IterableWrapper([{'a': 1, 'b': 2}, {'c': 3, 'a': 1}])
>>> index_dp = dp.add_index("order")
>>> list(index_dp)
[{'a': 1, 'b': 2, 'order': 0}, {'c': 3, 'a': 1, 'order': 1}]

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources