code: def object_to_numpy(
      data, expected_dtype=None, expected_ndim=None
  ) -> t.Union[np.ndarray, Number, str]:
      """Convert an object to a numpy object.
  
      Returns
      -------
      t.Union[np.ndarray, Number, str]
          A numpy object or a single object (number/str) for provided data.
      """
      if data is None:
          return None
      if is_torch_object(data):
          result = data.cpu().detach().numpy()
      elif is_tensorflow_object(data):
          result = data.cpu().numpy()
      elif isinstance(data, np.ndarray):
          result = data
      elif isinstance(data, (Number, str)):
          return data
      else:
          result = np.array(data)
  
      if expected_dtype is not None:
          result = result.astype(expected_dtype)
      if len(result.shape) == 0:
          result = result.item()
      elif (
          len(result.shape) == 1
          and result.shape[0] > 0
          and expected_ndim == 2
      ):
          result = result.reshape(1, result.shape[0])
      return result
  
imports: import random
  import sys
  import typing
  from collections import Counter
  from enum import Enum
  from numbers import Number
  import numpy
  from typing_extensions import NotRequired, TypedDict
  from deepchecks.core.errors import DatasetValidationError
  from deepchecks.utils.logger import get_logger
label_desc: Use image node_id 2 for calling a global function with example usage: object_to_numpy(data, expected_dtype, expected_ndim) and returns: result, None, data