code: def asnumpy_or_asscalar(
      data: Union[NDArray, list, tuple]
  ) -> Union[np.ndarray, np.number, list, tuple]:
      """
      Convert NDArray (or list or tuple of NDArray) to numpy. If shape is (1,), then convert to scalar instead.
      NOTE: This behavior is consistent with tensorflow
      :param data: NDArray or list or tuple of NDArray
      :return: data converted to numpy ndarray or to numpy scalar
      """
      if isinstance(data, list):
          data = [asnumpy_or_asscalar(d) for d in data]
      elif isinstance(data, tuple):
          data = tuple(asnumpy_or_asscalar(d) for d in data)
      elif isinstance(data, NDArray):
          data = (
              data.asscalar() if data.shape == (1,) else data.asnumpy()
          )
      else:
          raise TypeError(
              "Unsupported data type: {}".format(type(data))
          )
      return data
  
imports: import inspect
  from typing import Any, Dict, Generator, Iterable, List, Tuple, Union
  from types import ModuleType
  import mxnet
  from mxnet import gluon, nd
  from mxnet.ndarray import NDArray
  import numpy
  from rl_coach.core_types import GradientClippingMethod
label_desc: Use image node_id 2 for calling a global function with example usage: asnumpy_or_asscalar(data) and returns: data