code: def _convert_to_array_value(
      array: np.ndarray,
  ) -> metrics_for_slice_pb2.ArrayValue:
      """Converts NumPy array to ArrayValue."""
      result = metrics_for_slice_pb2.ArrayValue()
      result.shape[:] = array.shape
      if array.dtype == "int32":
          result.data_type = metrics_for_slice_pb2.ArrayValue.INT32
          result.int32_values[:] = array.flatten()
      elif array.dtype == "int64":
          result.data_type = metrics_for_slice_pb2.ArrayValue.INT64
          result.int64_values[:] = array.flatten()
      elif array.dtype == "float32":
          result.data_type = metrics_for_slice_pb2.ArrayValue.FLOAT32
          result.float32_values[:] = array.flatten()
      elif array.dtype == "float64":
          result.data_type = metrics_for_slice_pb2.ArrayValue.FLOAT64
          result.float64_values[:] = array.flatten()
      else:
          # For all other types, cast to string and convert to bytes.
          result.data_type = metrics_for_slice_pb2.ArrayValue.BYTES
          result.bytes_values[:] = [
              tf.compat.as_bytes(x) for x in array.astype(str).flatten()
          ]
      return result
  
imports: import itertools
  import os
  from typing import Any, Dict, Iterable, Iterator, List, Optional, Tuple, Union
  from absl import logging
  import apache_beam
  import numpy
  import pyarrow
  import tensorflow
  from tensorflow_model_analysis import constants
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.evaluators import evaluator
  from tensorflow_model_analysis.evaluators import metrics_validator
  from tensorflow_model_analysis.metrics import calibration_plot
  from tensorflow_model_analysis.metrics import confusion_matrix_plot
  from tensorflow_model_analysis.metrics import metric_specs
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.post_export_metrics import metric_keys
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.proto import metrics_for_slice_pb2
  from tensorflow_model_analysis.proto import validation_result_pb2
  from tensorflow_model_analysis.slicer import slicer_lib
  from tensorflow_model_analysis.utils import math_util
  from tensorflow_model_analysis.writers import writer
  from google.protobuf import wrappers_pb2
label_desc: Use image node_id 8 for calling a global function with example usage: _convert_to_array_value(array) and returns: result