Learn R Programming

tfdatasets (version 2.17.0)

dataset_enumerate: 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

Run this code
if (FALSE) {
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)
}

Run the code above in your browser using DataLab