code: def create_random_explanation(
      data: Data,
      node_mask_type: Optional[Union[MaskType, str]] = None,
      edge_mask_type: Optional[Union[MaskType, str]] = None,
  ):
      if node_mask_type is not None:
          node_mask_type = MaskType(node_mask_type)
      if edge_mask_type is not None:
          edge_mask_type = MaskType(edge_mask_type)
  
      if node_mask_type == MaskType.object:
          node_mask = torch.rand(data.x.size(0), 1)
      elif node_mask_type == MaskType.common_attributes:
          node_mask = torch.rand(1, data.x.size(1))
      elif node_mask_type == MaskType.attributes:
          node_mask = torch.rand_like(data.x)
      else:
          node_mask = None
  
      if edge_mask_type == MaskType.object:
          edge_mask = torch.rand(data.edge_index.size(1))
      else:
          edge_mask = None
  
      return Explanation(  # Create explanation.
          node_mask=node_mask,
          edge_mask=edge_mask,
          x=data.x,
          edge_index=data.edge_index,
          edge_attr=data.edge_attr,
      )
  
file_path: pytorch_geometric/test/explain/test_explanation.py
imports: import os.path
  from typing import Optional, Union
  import pytest
  import torch
  from torch_geometric.data import Data
  from torch_geometric.explain import Explanation
  from torch_geometric.explain.config import MaskType
  from torch_geometric.testing import withPackage
label_desc: Use image node_id 1 for calling a global function with example usage: create_random_explanation(data, node_mask_type, edge_mask_type) and returns: Explanation