Args: ds (DataFlow): input DataFlow which produces either list or dict. func (TYPE -> TYPE|None): takes ``dp[index]``, returns a new value for ``dp[index]``. Return None to discard/skip this datapoint. index (int or str): index or key of t
(self, ds, func, index=0)
| 336 | ds = MapDataComponent(ds, lambda img: img * 255, 0) # map the 0th component |
| 337 | """ |
| 338 | def __init__(self, ds, func, index=0): |
| 339 | """ |
| 340 | Args: |
| 341 | ds (DataFlow): input DataFlow which produces either list or dict. |
| 342 | func (TYPE -> TYPE|None): takes ``dp[index]``, returns a new value for ``dp[index]``. |
| 343 | Return None to discard/skip this datapoint. |
| 344 | index (int or str): index or key of the component. |
| 345 | """ |
| 346 | self._index = index |
| 347 | self._func = func |
| 348 | super(MapDataComponent, self).__init__(ds, self._mapper) |
| 349 | |
| 350 | def _mapper(self, dp): |
| 351 | r = self._func(dp[self._index]) |