code: def percentile(
      x: NdarrayOrTensor,
      q,
      dim: int | None = None,
      keepdim: bool = False,
      **kwargs,
  ) -> NdarrayOrTensor | float | int:
      """`np.percentile` with equivalent implementation for torch.
  
      Pytorch uses `quantile`. For more details please refer to:
      https://pytorch.org/docs/stable/generated/torch.quantile.html.
      https://numpy.org/doc/stable/reference/generated/numpy.percentile.html.
  
      Args:
          x: input data.
          q: percentile to compute (should in range 0 <= q <= 100).
          dim: the dim along which the percentiles are computed. default is to compute the percentile
              along a flattened version of the array.
          keepdim: whether the output data has dim retained or not.
          kwargs: if `x` is numpy array, additional args for `np.percentile`, more details:
              https://numpy.org/doc/stable/reference/generated/numpy.percentile.html.
  
      Returns:
          Resulting value (scalar)
      """
      q_np = convert_data_type(
          q, output_type=np.ndarray, wrap_sequence=True
      )[0]
      if ((q_np < 0) | (q_np > 100)).any():
          raise ValueError(
              f"q values must be in [0, 100], got values: {q}."
          )
      result: NdarrayOrTensor | float | int
      if isinstance(x, np.ndarray) or (
          isinstance(x, torch.Tensor) and torch.numel(x) > 1_000_000
      ):  # pytorch#64947
          _x = convert_data_type(x, output_type=np.ndarray)[0]
          result = np.percentile(
              _x, q_np, axis=dim, keepdims=keepdim, **kwargs
          )
          result = convert_to_dst_type(result, x)[0]
      else:
          q = convert_to_dst_type(q_np / 100.0, x)[0]
          result = torch.quantile(x, q, dim=dim, keepdim=keepdim)
      return result
  
imports: from __future__ import annotations
  from collections.abc import Sequence
  from typing import TypeVar
  import numpy
  import torch
  from monai.config.type_definitions import NdarrayOrTensor, NdarrayTensor
  from monai.utils.misc import is_module_ver_at_least
  from monai.utils.type_conversion import convert_data_type, convert_to_dst_type
label_desc: Use image node_id 5 for calling a global function with example usage: percentile(x, q, dim, keepdim) and returns: result