import tensorflow as tf

        num_episodes = tf.minimum(x=num_episodes, y=self.episode_count)
        assignment = tf.assign(
            ref=self.episode_indices[:self.episode_count - num_episodes],
            value=self.episode_indices[num_episodes: self.episode_count]
        )

        # Decrement episode count.
        with tf.control_dependencies(control_inputs=(assignment,)):
            assignment = tf.assign_sub(ref=self.episode_count, value=num_episodes)

        # Assign new observations.
        with tf.control_dependencies(control_inputs=(assignment,)):
            assignments = list()
            for name in sorted(states):
                assignments.append(tf.scatter_update(
                    ref=self.states_memory[name],
                    indices=indices,
                    updates=states[name]
                ))
            for name in sorted(internals):
                assignments.append(tf.scatter_update(
                    ref=self.internals_memory[name],
                    indices=indices,
                    updates=internals[name]
                ))
            for name in sorted(actions):
                assignments.append(tf.scatter_update(
                    ref=self.actions_memory[name],
