code: def get_batch(self, batch_size=256, max_len=20):
      batch_inds = np.random.choice(
          np.arange(self.num_trajectories),
          size=batch_size,
          replace=True,
          p=self.p_sample,  # reweights so we sample according to timesteps
      )
  
      s, a, r, d, rtg, timesteps, mask = [], [], [], [], [], [], []
      for i in range(batch_size):
          traj = self.trajectories[int(self.sorted_inds[batch_inds[i]])]
          si = random.randint(0, traj["rewards"].shape[0] - 1)
  
          # get sequences from dataset
          s.append(
              traj["observations"][si : si + max_len].reshape(
                  1, -1, self.state_dim
              )
          )
          a.append(
              traj["actions"][si : si + max_len].reshape(
                  1, -1, self.act_dim
              )
          )
          r.append(traj["rewards"][si : si + max_len].reshape(1, -1, 1))
          if "terminals" in traj:
              d.append(
                  traj["terminals"][si : si + max_len].reshape(1, -1)
              )
          else:
              d.append(traj["dones"][si : si + max_len].reshape(1, -1))
          timesteps.append(
              np.arange(si, si + s[-1].shape[1]).reshape(1, -1)
          )
          timesteps[-1][timesteps[-1] >= self.max_ep_len] = (
              self.max_ep_len - 1
          )  # padding cutoff
          rtg.append(
              self.discount_cumsum(traj["rewards"][si:], gamma=1.0)[
                  : s[-1].shape[1] + 1
              ].reshape(1, -1, 1)
          )
          if rtg[-1].shape[1] <= s[-1].shape[1]:
              rtg[-1] = np.concatenate(
                  [rtg[-1], np.zeros((1, 1, 1))], axis=1
              )
  
          # padding and state + reward normalization
          tlen = s[-1].shape[1]
          s[-1] = np.concatenate(
              [np.zeros((1, max_len - tlen, self.state_dim)), s[-1]],
              axis=1,
          )
          s[-1] = (s[-1] - self.state_mean) / self.state_std
          a[-1] = np.concatenate(
              [
                  np.ones((1, max_len - tlen, self.act_dim)) * -10.0,
                  a[-1],
              ],
              axis=1,
          )
          r[-1] = np.concatenate(
              [np.zeros((1, max_len - tlen, 1)), r[-1]], axis=1
          )
          d[-1] = np.concatenate(
              [np.ones((1, max_len - tlen)) * 2, d[-1]], axis=1
          )
          rtg[-1] = (
              np.concatenate(
                  [np.zeros((1, max_len - tlen, 1)), rtg[-1]], axis=1
              )
              / self.scale
          )
          timesteps[-1] = np.concatenate(
              [np.zeros((1, max_len - tlen)), timesteps[-1]], axis=1
          )
          mask.append(
              np.concatenate(
                  [np.zeros((1, max_len - tlen)), np.ones((1, tlen))],
                  axis=1,
              )
          )
  
      device = self.device
      s = torch.from_numpy(np.concatenate(s, axis=0)).to(
          dtype=torch.float32, device=device
      )
      a = torch.from_numpy(np.concatenate(a, axis=0)).to(
          dtype=torch.float32, device=device
      )
      r = torch.from_numpy(np.concatenate(r, axis=0)).to(
          dtype=torch.float32, device=device
      )
      d = torch.from_numpy(np.concatenate(d, axis=0)).to(
          dtype=torch.long, device=device
      )
      rtg = torch.from_numpy(np.concatenate(rtg, axis=0)).to(
          dtype=torch.float32, device=device
      )
      timesteps = torch.from_numpy(
          np.concatenate(timesteps, axis=0)
      ).to(dtype=torch.long, device=device)
      mask = torch.from_numpy(np.concatenate(mask, axis=0)).to(
          device=device
      )
  
      return s, a, r, d, rtg, timesteps, mask
  
file_path: PARL/benchmark/torch/DT/data_loader.py
imports: import numpy
  import pickle
  import random
  import torch
  from parl.utils import logger
label_desc: Use image node_id 2 for calling the DataLoader obj's underlying member method code with example usage: obj.get_batch(batch_size, max_len) and returns: s,  a,  r,  d,  rtg,  timesteps,  mask