code: def avg_pool3d(
      x: np.ndarray,
      kernel: Union[int, Tuple[int], Tuple[int, int, int]],
      strides: Union[int, Tuple[int], Tuple[int, int, int]],
      padding: Union[str, int, List[Tuple[int, int]]],
      /,
      *,
      data_format: str = "NDHWC",
      count_include_pad: bool = False,
      ceil_mode: bool = False,
      divisor_override: Optional[int] = None,
      out: Optional[np.ndarray] = None,
  ) -> np.ndarray:
      if isinstance(kernel, int):
          kernel = [kernel] * 3
      elif len(kernel) == 1:
          kernel = [kernel[0]] * 3
  
      if isinstance(strides, int):
          strides = [strides] * 3
      elif len(strides) == 1:
          strides = [strides[0]] * 3
  
      if data_format == "NCDHW":
          x = np.transpose(x, (0, 2, 3, 4, 1))
  
      x_shape = list(x.shape[1:4])
      padding, pad_specific, c = _get_padded_values(
          x_shape, kernel, strides, padding, ceil_mode, 3
      )
  
      x = np.pad(
          x,
          [
              (0, 0),
              *padding,
              (0, 0),
          ],
          constant_values=0.0,
      )
  
      x_shape = x.shape
      new_d = (x_shape[1] - kernel[0]) // strides[0] + 1
      new_h = (x_shape[2] - kernel[1]) // strides[1] + 1
      new_w = (x_shape[3] - kernel[2]) // strides[2] + 1
      new_shape = (
          [x_shape[0], new_d, new_h, new_w]
          + list(kernel)
          + [x_shape[-1]]
      )
      new_strides = (
          x.strides[0],
          x.strides[1] * strides[0],
          x.strides[2] * strides[1],
          x.strides[3] * strides[2],
          x.strides[1],
          x.strides[2],
          x.strides[3],
          x.strides[4],
      )
      # B x OH x OW x KH x KW x I
      sub_matrices = np.lib.stride_tricks.as_strided(
          x, new_shape, new_strides, writeable=False
      )
  
      # B x OH x OW x O
      if divisor_override is not None:
          res = np.sum(sub_matrices, axis=(4, 5, 6)) / divisor_override
      else:
          res = np.mean(sub_matrices, axis=(4, 5, 6))
  
      if (
          (not count_include_pad or ceil_mode)
          and any(pad_specific)
          and not divisor_override
      ):
          if not count_include_pad:
              num_padded_values = [
                  np.array(
                      ivy.map(
                          _get_num_padded_values,
                          constant={
                              "p": pad_specific[i],
                              "n": x.shape[i + 1] - pad_specific[i],
                              "k": kernel[i],
                              "s": strides[i],
                          },
                          unique={
                              "i": np.arange(res.shape[i + 1]),
                          },
                      ),
                      dtype=res.dtype,
                  )
                  for i in range(3)
              ]
          else:
              num_padded_values = []
              for i in range(3):
                  num_pad = np.zeros(res.shape[i + 1], dtype=res.dtype)
                  num_pad[-1] = c[i]
                  num_padded_values.append(num_pad)
          num_padded_values1 = num_padded_values[0].reshape((-1, 1, 1))
          num_padded_values2 = num_padded_values[1].reshape((1, -1, 1))
          num_padded_values3 = num_padded_values[2].reshape((1, 1, -1))
          num_padded_values = (
              num_padded_values1 * kernel[1] * kernel[2]
              + num_padded_values2 * kernel[0] * kernel[2]
              + num_padded_values3 * kernel[0] * kernel[1]
              + num_padded_values1
              * num_padded_values2
              * num_padded_values3
              - num_padded_values1 * num_padded_values2 * kernel[2]
              - num_padded_values1 * num_padded_values3 * kernel[1]
              - num_padded_values2 * num_padded_values3 * kernel[0]
          )
          kernel_mul = np.prod(kernel)
          res = (kernel_mul * res) / (
              kernel_mul - np.expand_dims(num_padded_values, -1)
          )
      if data_format == "NCDHW":
          return np.transpose(res, (0, 4, 1, 2, 3))
      return res
  
imports: import math
  import numpy
  from typing import Optional, Union, Tuple, List, Literal, Sequence, Callable
  import ivy
  from ivy.functional.ivy.layers import _handle_padding, _get_num_padded_values, _validate_max_pool_params, _depth_max_pooling_helper
  from ivy.functional.backends.numpy.layers import _add_dilations
  from ivy.functional.ivy.experimental.layers import _padding_ceil_mode
  from ivy.func_wrapper import with_supported_dtypes
  from ivy.func_wrapper import with_unsupported_dtypes
  from .None import backend_version
label_desc: Use image node_id 8 for calling a global function with example usage: avg_pool3d() and returns: res, np