code: def safe_to_scalar(arr: Any) -> Any:
      """Returns array/list as a scalar, 0.0 if empty else raises ValueError."""
      if isinstance(arr, list):
          if not arr:
              return 0.0
          else:
              raise ValueError(
                  "Array should have exactly 1 value to a Python scalar"
              )
      else:
          if arr.size == 0:
              return 0.0
          elif arr.size == 1:
              return arr.item()
          else:
              raise ValueError(
                  "Array should have exactly 1 value to a Python scalar"
              )
  
imports: import inspect
  import math
  from typing import Any, Callable, Dict, Iterable, Iterator, List, Mapping, Optional, Tuple, Union
  import numpy
  import tensorflow
  from tensorflow_model_analysis import constants
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.utils import util
  from tensorflow_metadata.proto.v0 import schema_pb2
label_desc: Use image node_id 12 for calling a global function with example usage: safe_to_scalar(arr) and returns: int, int, arr