code: def np_avgpool1d(x, pool_size, strides, padding, data_format):
      if data_format == "channels_first":
          x = x.swapaxes(1, 2)
      if isinstance(pool_size, (tuple, list)):
          pool_size = pool_size[0]
      if isinstance(strides, (tuple, list)):
          h_stride = strides[0]
      else:
          h_stride = strides
  
      if padding == "same":
          n_batch, h_x, ch_x = x.shape
          pad_value = _same_padding(h_x, pool_size, h_stride)
          npad = [(0, 0)] * x.ndim
          npad[1] = (0, pad_value)
          x = np.pad(x, pad_width=npad, mode="edge")
  
      n_batch, h_x, ch_x = x.shape
      out_h = int((h_x - pool_size) / h_stride) + 1
  
      stride_shape = (n_batch, out_h, ch_x, pool_size)
      strides = (
          x.strides[0],
          h_stride * x.strides[1],
          x.strides[2],
          x.strides[1],
      )
      windows = as_strided(x, shape=stride_shape, strides=strides)
      out = np.mean(windows, axis=(3,))
      if data_format == "channels_first":
          out = out.swapaxes(1, 2)
      return out
  
imports: import numpy
  import pytest
  from absl.testing import parameterized
  from numpy.lib.stride_tricks import as_strided
  from keras import backend
  from keras import layers
  from keras import testing
label_desc: Use image node_id 2 for calling a global function with example usage: np_avgpool1d(x, pool_size, strides, padding, data_format) and returns: out