code: def slice_episodes(episodes, slice_size):
      sliced = []
      for eps in episodes.split():
          splits = math.ceil(eps.lengths[0] / slice_size)
          split_indices = np.array_split(
              np.arange(eps.lengths[0]), splits
          )
          next_obs = eps.next_observations
          for indices in split_indices:
              last_obs = np.asarray([next_obs[indices[-1]]])
              t = EpisodeBatch(
                  env_spec=eps.env_spec,
                  episode_infos={},
                  observations=eps.observations[indices],
                  last_observations=last_obs,
                  actions=eps.actions[indices],
                  rewards=eps.rewards[indices],
                  step_types=eps.step_types[indices],
                  env_infos={
                      k: v[indices] for (k, v) in eps.env_infos.items()
                  },
                  agent_infos={
                      k: v[indices]
                      for (k, v) in eps.agent_infos.items()
                  },
                  lengths=np.asarray([len(indices)], dtype="l"),
              )
              sliced.append(t)
      return sliced
  
file_path: garage/tests/garage/sampler/test_fragment_worker.py
imports: import math
  import pprint
  import numpy
  import pytest
  from garage import EpisodeBatch, StepType
  from garage.envs import GridWorldEnv, PointEnv
  from garage.experiment.task_sampler import SetTaskSampler
  from garage.np.policies import FixedPolicy, ScriptedPolicy
  from garage.sampler import FragmentWorker, LocalSampler, WorkerFactory
label_desc: Use image node_id 6 for calling a global function with example usage: slice_episodes(episodes, slice_size) and returns: sliced