dataset_enumerate: Enumerates the elements of this dataset

View source: R/dataset_methods.R

dataset_enumerateR Documentation

Enumerates the elements of this dataset

Description

Enumerates the elements of this dataset

Usage

dataset_enumerate(dataset, start = 0L)

Arguments

dataset

A tensorflow dataset

start

An integer (coerced to a tf$int64 scalar tf.Tensor), representing the start value for enumeration.

Details

It is similar to python's enumerate, this transforms a sequence of elements into a sequence of list(index, element), where index is an integer that indicates the position of the element in the sequence.

Examples

## Not run: 
dataset <- tensor_slices_dataset(100:103) %>%
  dataset_enumerate()

iterator <- reticulate::as_iterator(dataset)
reticulate::iter_next(iterator) # list(0, 100)
reticulate::iter_next(iterator) # list(1, 101)
reticulate::iter_next(iterator) # list(2, 102)
reticulate::iter_next(iterator) # list(3, 103)
reticulate::iter_next(iterator) # NULL (iterator exhausted)
reticulate::iter_next(iterator) # NULL (iterator exhausted)

## End(Not run)

rstudio/tfdatasets documentation built on July 22, 2024, 12:41 a.m.