code: def rolling_window(x, wsz, wnm=None, pad='wrap'):
      
  
      if wnm is None:
          wnm = tuple(np.array(x.shape) - np.array(wsz) + 1)
      else:
          over = np.clip(np.array(wsz) + np.array(wnm) - np.array(x.shape) - 1,
                         0, np.iinfo(int).max)
          if np.any(over > 0):
              psz = [(0, p) for p in over]
              x = np.pad(x, psz, mode=pad)
      outsz = wsz + wnm
      outstrd = x.strides + x.strides
      return np.lib.stride_tricks.as_strided(x, outsz, outstrd)
docs: Use :func:`numpy.lib.stride_tricks.as_strided` to construct a view
      of the input array that represents different positions of a rolling
      window as additional axes of the array. If the number of shifts
      requested is such that the window extends beyond the boundary of the
      input array, it is padded before the view is constructed. For
      example, if ``x`` is 4 x 5 array, the output of
      ``y = rolling_window(x, (3, 3))`` is a 3 x 3 x 2 x 3 array, with the
      first window position indexed as ``y[..., 0, 0]``.
  
      Parameters
      ----------
      x : ndarray
        Input array
      wsz : tuple
        Window size
      wnm : tuple, optional (default None)
        Number of shifts of window on each axis. If None, the number of
        shifts is set so that the end sample in the array is also the end
        sample in the final window position.
      pad : string, optional (default 'wrap')
        A pad mode specification for :func:`numpy.pad`
  
      Returns
      -------
      xw : ndarray
        An array of shape wsz + wnm representing all requested shifts of
        the window within the input array