code: def group_data(
      data,
      cluster=None,
      unique_pos_indices=None,
      mode="last",
      skip_keys=[],
  ):
      """Group data based on indices in cluster.
      The option ``mode`` controls how data gets agregated within each cluster.
  
      Parameters
      ----------
      data : Data
          [description]
      cluster : torch.Tensor
          Tensor of the same size as the number of points in data. Each element is the cluster index of that point.
      unique_pos_indices : torch.tensor
          Tensor containing one index per cluster, this index will be used to select features and labels
      mode : str
          Option to select how the features and labels for each voxel is computed. Can be ``last`` or ``mean``.
          ``last`` selects the last point falling in a voxel as the representent, ``mean`` takes the average.
      skip_keys: list
          Keys of attributes to skip in the grouping
      """
  
      assert mode in ["mean", "last"]
      if mode == "mean" and cluster is None:
          raise ValueError(
              "In mean mode the cluster argument needs to be specified"
          )
      if mode == "last" and unique_pos_indices is None:
          raise ValueError(
              "In last mode the unique_pos_indices argument needs to be specified"
          )
  
      num_nodes = data.num_nodes
      for key, item in data:
          if bool(re.search("edge", key)):
              raise ValueError("Edges not supported. Wrong data type.")
          if key in skip_keys:
              continue
  
          if torch.is_tensor(item) and item.size(0) == num_nodes:
              if (
                  mode == "last"
                  or key == "batch"
                  or key == SaveOriginalPosId.KEY
              ):
                  data[key] = item[unique_pos_indices]
              elif mode == "mean":
                  is_item_bool = item.dtype == torch.bool
                  if is_item_bool:
                      item = item.int()
                  if key in _INTEGER_LABEL_KEYS:
                      item_min = item.min()
                      item = F.one_hot(item - item_min)
                      item = scatter_add(item, cluster, dim=0)
                      data[key] = item.argmax(dim=-1) + item_min
                  else:
                      data[key] = scatter_mean(item, cluster, dim=0)
                  if is_item_bool:
                      data[key] = data[key].bool()
      return data
  
imports: from typing import *
  import numpy
  import numpy
  import random
  import scipy
  import re
  import torch
  import logging
  import torch.nn.functional
  from torch_scatter import scatter_mean, scatter_add
  from torch_geometric.nn.pool.consecutive import consecutive_cluster
  from torch_geometric.nn import voxel_grid
  from torch_geometric.data import Data
  from torch_cluster import grid_cluster
label_desc: Use image node_id 2 for calling a global function with example usage: group_data(data, cluster, unique_pos_indices, mode, skip_keys) and returns: data