code: def scatter_numpy(dim, index, src):
      """
      Writes all values from the Tensor src into dst at the indices specified in the index Tensor.
  
      :param dim: The axis along which to index
      :param index: The indices of elements to scatter
      :param src: The source element(s) to scatter
      :return: dst
      """
      dst = src.copy()
      idx_xsection_shape = index.shape[:dim] + index.shape[dim + 1 :]
      dst_xsection_shape = dst.shape[:dim] + dst.shape[dim + 1 :]
      if idx_xsection_shape != dst_xsection_shape:
          raise ValueError(
              "Except for dimension "
              + str(dim)
              + ", all dimensions of index and output should be the same size"
          )
      if (index >= dst.shape[dim]).any() or (index < 0).any():
          raise IndexError(
              "The values of index must be between 0 and {}.".format(
                  dst.shape[dim] - 1
              )
          )
  
      def make_slice(arr, dim, i):
          slc = [slice(None)] * arr.ndim
          slc[dim] = i
          return tuple(slc)
  
      # We use index and dim parameters to create idx
      # idx is in a form that can be used as a NumPy advanced index for scattering of src param.
      idx = [
          [
              *np.indices(idx_xsection_shape).reshape(
                  index.ndim - 1, -1
              ),
              index[make_slice(index, dim, i)].reshape(1, -1)[0],
          ]
          for i in range(index.shape[dim])
      ]
      idx = list(np.concatenate(idx, axis=1))
      idx.insert(dim, idx.pop())
  
      if not np.isscalar(src):
          if index.shape[dim] > src.shape[dim]:
              raise IndexError(
                  "Dimension "
                  + str(dim)
                  + "of index can not be bigger than that of src "
              )
          src_xsection_shape = src.shape[:dim] + src.shape[dim + 1 :]
          if idx_xsection_shape != src_xsection_shape:
              raise ValueError(
                  "Except for dimension "
                  + str(dim)
                  + ", all dimensions of index and src should be the same size"
              )
          # src_idx is a NumPy advanced index for indexing of elements in the src
          src_idx = list(idx)
          src_idx.pop(dim)
          src_idx.insert(
              dim,
              np.repeat(
                  np.arange(index.shape[dim]),
                  np.prod(idx_xsection_shape),
              ),
          )
          dst[tuple(idx)] = src[tuple(src_idx)]
      else:
          dst[idx] = src
      return dst
  
file_path: PaddleHub/modules/image/Image_gan/style_transfer/stylepro_artistic/processor.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  import base64
  import cv2
  import numpy
label_desc: Use image node_id 5 for calling a global function with example usage: scatter_numpy(dim, index, src) and returns: dst, tuple