def add_data(self, name: str, value=None, item_shape: tuple=None, with_after_last: Optional[bool]=False):
    '\n        Add a new data field to the step sequence.\n\n        :param name: string for the name\n        :param value: the data\n        :param item_shape: shape to store the data in\n        :param with_after_last: `True` if there is one more element than the length (e.g. last observation)\n        '
    if (name in self._data_names):
        raise pyrado.KeyErr(msg=f'Trying to add a duplicate data field for {name}!')
    if (value is None):
        ro_length = self.length
        if with_after_last:
            ro_length += 1
        if (self._data_format == 'torch'):
            value = to.zeros((to.Size([ro_length]) + to.Size(item_shape)))
        else:
            value = np.array(((ro_length,) + item_shape))
    else:
        self._validate_data_size(name, value)
        if (not isinstance(value, (np.ndarray, to.Tensor))):
            value = stack_to_format(value, self._data_format)
        else:
            value = to_format(value, self._data_format)
    self._data_names.append(name)
    self.__dict__[name] = value
Add a new data field to the step sequence.

:param name: string for the name
:param value: the data
:param item_shape: shape to store the data in
:param with_after_last: `True` if there is one more element than the length (e.g. last observation)
def add_data(self, name: str, value=None, item_shape: tuple=None, with_after_last: Optional[bool]=False):
    '\n        Add a new data field to the step sequence.\n\n        :param name: string for the name\n        :param value: the data\n        :param item_shape: shape to store the data in\n        :param with_after_last: `True` if there is one more element than the length (e.g. last observation)\n        '
    if (name in self._data_names):
        raise pyrado.KeyErr(msg=f'Trying to add a duplicate data field for {name}!')
    if (value is None):
        ro_length = self.length
        if with_after_last:
            ro_length += 1
        if (self._data_format == 'torch'):
            value = to.zeros((to.Size([ro_length]) + to.Size(item_shape)))
        else:
            value = np.array(((ro_length,) + item_shape))
    else:
        self._validate_data_size(name, value)
        if (not isinstance(value, (np.ndarray, to.Tensor))):
            value = stack_to_format(value, self._data_format)
        else:
            value = to_format(value, self._data_format)
    self._data_names.append(name)
    self.__dict__[name] = value