code: def pooling_2d(
      x,
      mode,
      kernel,
      stride,
      pad,
      ignore_border=True,
      including_pad=True,
      dtype=np.float32,
  ):
      """ """
      assert mode in ["average", "sum", "max"]
  
      C, H, W = x.shape
      Ho = get_pool_out_size(
          H, kernel[0], pad[0], stride[0], ignore_border
      )
      Wo = get_pool_out_size(
          W, kernel[1], pad[1], stride[1], ignore_border
      )
      Hi = H + pad[0] + (pad[0] if ignore_border else kernel[0] - 1)
      Wi = W + pad[1] + (pad[1] if ignore_border else kernel[1] - 1)
  
      x_pad = np.ones((C, Hi, Wi), dtype=dtype)
      x_pad *= x.min() if mode == "max" else 0
      x_pad[:, pad[0] : pad[0] + H, pad[1] : pad[1] + W] = x
  
      if mode == "average":
          b_pad = np.zeros((C, Hi, Wi), dtype=np.uint)
          h_beg = int(not including_pad) * pad[0]
          w_beg = int(not including_pad) * pad[1]
          h_end = H + (1 + int(including_pad)) * pad[0]
          w_end = W + (1 + int(including_pad)) * pad[1]
          b_pad[:, h_beg:h_end, w_beg:w_end] = 1
  
      y = np.zeros((C, Ho, Wo), dtype=dtype)
  
      for c in range(C):
          for ho in range(Ho):
              for wo in range(Wo):
                  hi = ho * stride[0] + np.arange(0, kernel[0])
                  wi = wo * stride[1] + np.arange(0, kernel[1])
                  yy = y[c]
                  xx = x_pad[c]
                  if mode == "max":
                      yy[ho, wo] = xx[np.ix_(hi, wi)].max()
                  elif mode == "sum":
                      yy[ho, wo] = xx[np.ix_(hi, wi)].sum()
                  elif mode == "average":
                      pad_sum = xx[np.ix_(hi, wi)].sum()
                      pad_cnt = b_pad[c][np.ix_(hi, wi)].sum()
                      yy[ho, wo] = pad_sum / pad_cnt
      return y
  
imports: from __future__ import division
  from six.moves import range
  import itertools
  import numpy
label_desc: Use image node_id 10 for calling a global function with example usage: pooling_2d(x, mode, kernel, stride, pad, ignore_border, including_pad, dtype) and returns: y