code: def swap_layer_type(nn, layer_idx, replace_with, new_stride):
      """Swaps out the type of layer in layer_idx with replace_with"""
      if nn.layer_labels[layer_idx] == replace_with:
          raise ValueError(
              "Cannot replace layer %d with the same layer type (%s)."
              % (layer_idx, replace_with)
          )
      (
          layer_labels,
          num_units_in_each_layer,
          conn_mat,
          mandatory_child_attributes,
      ) = get_copies_from_old_nn(nn)
      layer_labels[layer_idx] = replace_with
      if nn.nn_class == "cnn":
          if is_a_pooling_layer_label(replace_with):
              num_units_in_each_layer[layer_idx] = None
          mandatory_child_attributes.strides[layer_idx] = new_stride
      return get_new_nn(
          nn,
          layer_labels,
          num_units_in_each_layer,
          conn_mat,
          mandatory_child_attributes,
      )
  
imports: from argparse import Namespace
  from copy import deepcopy
  import numpy
  from .neural_network import ConvNeuralNetwork, MultiLayerPerceptron, MLP_RECTIFIERS, MLP_SIGMOIDS, is_a_pooling_layer_label, is_a_conv_layer_label, CNNImageSizeMismatchException, CNNNoConvAfterIPException
  from ..utils.general_utils import reorder_list_or_array, reorder_rows_and_cols_in_matrix
  from ..utils.option_handler import get_option_specs, load_options
  from ..utils.reporters import get_reporter
label_desc: Use image node_id 17 for calling a global function with example usage: swap_layer_type(nn, layer_idx, replace_with, new_stride) and returns: get_new_nn