Shortcuts

Enumerator

class torchdata.datapipes.iter.Enumerator(source_datapipe: IterDataPipe[K], starting_index: int = 0)

Adds an index to an existing DataPipe through enumeration, with the index starting from 0 by default (functional name: enumerate).

Parameters:
  • source_datapipe – Iterable DataPipe being indexed

  • starting_index – Index from which enumeration will start

Example

>>> from torchdata.datapipes.iter import IterableWrapper
>>> dp = IterableWrapper(['a', 'b', 'c'])
>>> enum_dp = dp.enumerate()
>>> list(enum_dp)
[(0, 'a'), (1, 'b'), (2, 'c')]

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