def shuffled_batches(self, batch_size):
if batch_size >= self.num_envs * self.num_steps:<EOL><INDENT>yield self<EOL><DEDENT>else:<EOL><INDENT>rollouts_in_batch = batch_size // self.num_steps<EOL>batch_splits = math_util.divide_ceiling(self.num_envs, rollouts_in_batch)<EOL>indices = list(range(self.num_envs))<EOL>np.random.shuffle(indices)<EOL>for sub_indices in np.array_split(indices, batch_splits):<EOL><INDENT>yield Trajectories(<EOL>num_steps=self.num_steps,<EOL>num_envs=len(sub_indices),<EOL>environment_information=None,<EOL>transition_tensors={k: x[:, sub_indices] for k, x in self.transition_tensors.items()},<EOL>rollout_tensors={k: x[sub_indices] for k, x in self.rollout_tensors.items()},<EOL>)<EOL><DEDENT><DEDENT>
Generate randomized batches of data - only sample whole trajectories