code: def scatter_nd(
      indices: torch.Tensor,
      updates: torch.Tensor,
      /,
      shape: Optional[Union[ivy.NativeShape, Sequence[int]]] = None,
      *,
      reduction: str = "sum",
      out: Optional[torch.Tensor] = None,
  ) -> torch.Tensor:
      updates = torch.tensor(
          updates,
          dtype=(
              ivy.dtype(out, as_native=True)
              if ivy.exists(out)
              else ivy.default_dtype(item=updates, as_native=True)
          ),
      )
  
      expected_shape = (
          list(indices.shape[:-1])
          + list(out.shape[indices.shape[-1] :])
          if ivy.exists(out)
          else list(indices.shape[:-1])
          + list(shape[indices.shape[-1] :])
      )
      updates = _broadcast_to(updates, expected_shape)._data
  
      # implementation
      target_given = ivy.exists(out)
      if ivy.exists(shape) and target_given:
          ivy.utils.assertions.check_equal(
              ivy.Shape(out.shape), ivy.Shape(shape), as_array=False
          )
      shape = list(shape) if ivy.exists(shape) else list(out.shape)
      dtype = updates.dtype
      indices_shape = indices.shape
      num_index_dims = indices_shape[-1]
      result_dim_sizes_list = [
          _reduce(mul, shape[i + 1 :], 1) for i in range(len(shape) - 1)
      ] + [1]
      result_dim_sizes = torch.tensor(result_dim_sizes_list)
      implicit_indices_factor = int(
          result_dim_sizes[num_index_dims - 1].item()
      )
      flat_result_size = _reduce(mul, shape, 1)
      if reduction not in ["sum", "replace", "min", "max"]:
          raise ivy.utils.exceptions.IvyException(
              f'reduction is {reduction}, but it must be one of "sum", "min", "max" or'
              ' "replace"'
          )
      if target_given:
          flat_output = torch.reshape(out, (flat_result_size,)).detach()
      else:
          flat_output = torch.zeros(flat_result_size, dtype=dtype)
      flat_updates = torch.reshape(updates, (-1,))
      new_shape = [1] * (len(indices_shape) - 1) + [num_index_dims]
      indices_scales = torch.reshape(
          result_dim_sizes[0:num_index_dims], new_shape
      )
      indices_for_flat_tiled = torch.reshape(
          torch.sum(indices * indices_scales, -1, keepdim=True), (-1, 1)
      ).repeat(*[1, implicit_indices_factor])
      implicit_indices = torch.unsqueeze(
          torch.arange(implicit_indices_factor), 0
      ).repeat(*[indices_for_flat_tiled.shape[0], 1])
      indices_for_flat = indices_for_flat_tiled + implicit_indices
      flat_indices_for_flat = torch.reshape(
          indices_for_flat, (-1,)
      ).type(torch.long)
      global torch_scatter
      if torch_scatter is None:
          try:
              import torch_scatter as torch_scatter
          except ImportError as e:
              raise ivy.utils.exceptions.IvyException(
                  "Unable to import torch_scatter, verify this is correctly installed."
              ) from e
      if reduction == "replace":
          flat_output[flat_indices_for_flat] = flat_updates
          flat_scatter = flat_output
      else:
          flat_scatter = torch_scatter.scatter(
              flat_updates,
              flat_indices_for_flat,
              out=flat_output.clone(),
              reduce=reduction,
          )
      res = torch.reshape(flat_scatter, list(shape))
      if ivy.exists(out):
          return ivy.inplace_update(out, res)
      return res
  
imports: from functools import reduce
  from numbers import Number
  from operator import mul
  from typing import Optional, Union, Sequence, Callable, List, Tuple
  import numpy
  import torch
  import ivy
  from ivy.func_wrapper import with_unsupported_dtypes, _update_torch_views
  from .None import backend_version, is_variable
  from ...ivy.general import _broadcast_to
label_desc: Use image node_id 23 for calling a global function with example usage: scatter_nd(shape) and returns: res, ivy