code: def to_scipy_sparse_matrix(
      edge_index: Tensor,
      edge_attr: Optional[Tensor] = None,
      num_nodes: Optional[int] = None,
  ) -> scipy.sparse.coo_matrix:
      r"""Converts a graph given by edge indices and edge attributes to a scipy
      sparse matrix.
  
      Args:
          edge_index (LongTensor): The edge indices.
          edge_attr (Tensor, optional): Edge weights or multi-dimensional
              edge features. (default: :obj:`None`)
          num_nodes (int, optional): The number of nodes, *i.e.*
              :obj:`max_val + 1` of :attr:`index`. (default: :obj:`None`)
  
      Examples:
          >>> edge_index = torch.tensor([
          ...     [0, 1, 1, 2, 2, 3],
          ...     [1, 0, 2, 1, 3, 2],
          ... ])
          >>> to_scipy_sparse_matrix(edge_index)
          <4x4 sparse matrix of type '<class 'numpy.float32'>'
              with 6 stored elements in COOrdinate format>
      """
      row, col = edge_index.cpu()
  
      if edge_attr is None:
          edge_attr = torch.ones(row.size(0))
      else:
          edge_attr = edge_attr.view(-1).cpu()
          assert edge_attr.size(0) == row.size(0)
  
      N = maybe_num_nodes(edge_index, num_nodes)
      out = scipy.sparse.coo_matrix(
          (edge_attr.numpy(), (row.numpy(), col.numpy())), (N, N)
      )
      return out
  
file_path: pytorch_geometric/torch_geometric/utils/convert.py
imports: from collections import defaultdict
  from typing import Any, Dict, Iterable, List, Literal, Optional, Tuple, Union
  import scipy.sparse
  import torch
  from torch import Tensor
  from torch.utils.dlpack import from_dlpack, to_dlpack
  import torch_geometric
  from torch_geometric.utils.num_nodes import maybe_num_nodes
label_desc: Use image node_id 1 for calling a global function with example usage: to_scipy_sparse_matrix(edge_index, edge_attr, num_nodes) and returns: out