code: def upload_numpy_to_s3_shards(
      num_shards,
      s3,
      bucket,
      key_prefix,
      array,
      labels=None,
      encrypt=False,
  ):
      """Upload the training ``array`` and ``labels`` arrays to ``num_shards``.
  
      S3 objects, stored in "s3:// ``bucket`` / ``key_prefix`` /". Optionally
      ``encrypt`` the S3 objects using AES-256.
  
      Args:
          num_shards:
          s3:
          bucket:
          key_prefix:
          array:
          labels:
          encrypt:
      """
      shards = _build_shards(num_shards, array)
      if labels is not None:
          label_shards = _build_shards(num_shards, labels)
      uploaded_files = []
      if key_prefix[-1] != "/":
          key_prefix = key_prefix + "/"
      extra_put_kwargs = (
          {"ServerSideEncryption": "AES256"} if encrypt else {}
      )
      try:
          for shard_index, shard in enumerate(shards):
              with tempfile.TemporaryFile() as file:
                  if labels is not None:
                      write_numpy_to_dense_tensor(
                          file, shard, label_shards[shard_index]
                      )
                  else:
                      write_numpy_to_dense_tensor(file, shard)
                  file.seek(0)
                  shard_index_string = str(shard_index).zfill(
                      len(str(len(shards)))
                  )
                  file_name = "matrix_{}.pbr".format(shard_index_string)
                  key = key_prefix + file_name
                  logger.debug(
                      "Creating object %s in bucket %s", key, bucket
                  )
                  s3.Object(bucket, key).put(
                      Body=file, **extra_put_kwargs
                  )
                  uploaded_files.append(file_name)
          manifest_key = key_prefix + ".amazon.manifest"
          manifest_str = json.dumps(
              [{"prefix": "s3://{}/{}".format(bucket, key_prefix)}]
              + uploaded_files
          )
          s3.Object(bucket, manifest_key).put(
              Body=manifest_str.encode("utf-8"), **extra_put_kwargs
          )
          return "s3://{}/{}".format(bucket, manifest_key)
      except Exception as ex:  # pylint: disable=broad-except
          try:
              for file in uploaded_files:
                  s3.Object(bucket, key_prefix + file).delete()
          finally:
              raise ex
  
imports: from __future__ import absolute_import
  import json
  import logging
  import tempfile
  from typing import Union, Optional, Dict
  from six.moves.urllib.parse import urlparse
  from sagemaker import image_uris, s3_utils
  from sagemaker.amazon import validation
  from sagemaker.amazon.hyperparameter import Hyperparameter
  from sagemaker.amazon.common import write_numpy_to_dense_tensor
  from sagemaker.deprecations import renamed_warning
  from sagemaker.estimator import EstimatorBase, _TrainingJob
  from sagemaker.inputs import FileSystemInput, TrainingInput
  from sagemaker.utils import sagemaker_timestamp, check_and_get_run_experiment_config
  from sagemaker.workflow.entities import PipelineVariable
  from sagemaker.workflow.pipeline_context import runnable_by_pipeline
  from sagemaker.workflow import is_pipeline_variable
label_desc: Use image node_id 2 for calling a global function with example usage: upload_numpy_to_s3_shards(num_shards, s3, bucket, key_prefix, array, labels, encrypt) and returns: str