code: def create_tensor_value(np_tensor):
      """
      Return TensorValue.
      """
      builtin_type = numpy_type_to_builtin_type(np_tensor.dtype)
  
      value_type = create_valuetype_tensor(
          np_tensor.shape, types_to_proto_primitive(builtin_type)
      )
      val = pm.Value(type=value_type)
      t_val = val.immediateValue.tensor
  
      # Copy the tensor values from the input tensor
      t_field = _tensor_field_by_type(t_val, builtin_type)
  
      if 0 not in np_tensor.shape:
          if builtin_type == types.str:
              for x in np.nditer(np_tensor):
                  t_field.append(x.encode("utf-8"))
          elif builtin_type in IMMEDIATE_VALUE_TYPES_IN_BYTES:
              val.immediateValue.tensor.bytes.values = (
                  np_val_to_py_type(np_tensor)
              )
          else:
              for x in np_tensor.flatten():
                  t_field.append(np_val_to_py_type(x))
      else:  # This is an "empty" tensor (tensor with a dimension being size 0)
          _set_empty_tensor_field_by_type(t_val, builtin_type)
      return val
  
imports: import os
  import numpy
  import coremltools.proto.FeatureTypes_pb2
  import coremltools.proto.MIL_pb2
  from coremltools.converters.mil.mil import types
  from coremltools.converters.mil.mil.types import BUILTIN_TO_PROTO_TYPES, builtin_to_string, numpy_type_to_builtin_type, type_to_builtin_type
  from coremltools.converters.mil.mil.types.type_mapping import np_val_to_py_type
  from coremltools.models.utils import _WEIGHTS_DIR_NAME, _WEIGHTS_FILE_NAME
label_desc: Use image node_id 10 for calling a global function with example usage: create_tensor_value(np_tensor) and returns: val