docs: def upload_numpy_to_s3_shards(num_shards, s3, bucket, key_prefix, array, labels=None):
      """Upload the training ``array`` and ``labels`` arrays to ``num_shards`` s3 objects,
      stored in "s3://``bucket``/``key_prefix``/"."""
      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 + '/'
      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 {} in bucket {}".format(key, bucket))
                  s3.Object(bucket, key).put(Body=file)
                  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'))
          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