code: def _verify_np_shape(array: "npt.NDArray[Any]") -> "npt.NDArray[Any]":
      if len(array.shape) not in (2, 3):
          raise StreamlitAPIException(
              "Numpy shape has to be of length 2 or 3."
          )
      if len(array.shape) == 3 and array.shape[-1] not in (1, 3, 4):
          raise StreamlitAPIException(
              "Channel can only be 1, 3, or 4 got %d. Shape is %s"
              % (array.shape[-1], str(array.shape))
          )
  
      # If there's only one channel, convert is to x, y
      if len(array.shape) == 3 and array.shape[-1] == 1:
          array = array[:, :, 0]
  
      return array
  
imports: import base64
  import io
  import mimetypes
  import re
  from enum import IntEnum
  from typing import TYPE_CHECKING, List, Optional, Sequence, Union, cast
  from urllib.parse import urlparse
  import numpy
  from PIL import GifImagePlugin, Image, ImageFile
  from typing_extensions import Final, Literal, TypeAlias
  from streamlit import runtime
  from streamlit.errors import StreamlitAPIException
  from streamlit.logger import get_logger
  from streamlit.proto.Image_pb2 import ImageList
  from streamlit.runtime import caching
  from streamlit.runtime.metrics_util import gather_metrics
label_desc: Use image node_id 8 for calling a global function with example usage: _verify_np_shape(array) and returns: array