code: def to_mx_ndarray(
      data: Union[list, tuple, np.ndarray, NDArray, int, float],
      ctx: mx.Context = None,
  ) -> Union[List[NDArray], Tuple[NDArray], NDArray]:
      """
      Convert data to mx.nd.NDArray. Data can be a list or tuple of np.ndarray, int, or float or
      it can be np.ndarray, int, or float
      :param data: input data to be converted
      :param ctx: context of the data (CPU, GPU0, GPU1, etc.)
      :return: converted output data
      """
      if isinstance(data, list):
          data = [to_mx_ndarray(d, ctx=ctx) for d in data]
      elif isinstance(data, tuple):
          data = tuple(to_mx_ndarray(d, ctx=ctx) for d in data)
      elif isinstance(data, np.ndarray):
          data = nd.array(data, ctx=ctx)
      elif isinstance(data, NDArray):
          assert data.context == ctx
          pass
      elif isinstance(data, int) or isinstance(data, float):
          data = nd.array([data], ctx=ctx)
      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 1 for calling a global function with example usage: to_mx_ndarray(data, ctx) and returns: data