class_docstr: Agent of Cartpole env.
  
  Args:
      algorithm(parl.Algorithm): algorithm used to solve the problem.
docstr: Sample an action when given an observation
  
  Args:
      obs(np.float32): shape of (obs_dim,)
  
  Returns:
      action(int)
code: def sample(self, obs):
      """Sample an action when given an observation
  
      Args:
          obs(np.float32): shape of (obs_dim,)
  
      Returns:
          action(int)
      """
      obs = torch.tensor(obs, device=self.device, dtype=torch.float)
      prob = self.alg.predict(obs).cpu()
      prob = prob.data.numpy()
      action = np.random.choice(len(prob), 1, p=prob)[0]
      return action
  
file_path: PARL/benchmark/torch/QuickStart/cartpole_agent.py
imports: import parl
  import torch
  import numpy
label_desc: Use image node_id 2 for calling the CartpoleAgent obj's underlying member method code with example usage: obj.sample(obs) and returns: action