code: def rename_fields(base, namemapper):
      """
      Rename the fields from a flexible-datatype ndarray or recarray.
  
      Nested fields are supported.
  
      Parameters
      ----------
      base : ndarray
          Input array whose fields must be modified.
      namemapper : dictionary
          Dictionary mapping old field names to their new version.
  
      Examples
      --------
      >>> from numpy.lib import recfunctions as rfn
      >>> a = np.array([(1, (2, [3.0, 30.])), (4, (5, [6.0, 60.]))],
      ...   dtype=[('a', int),('b', [('ba', float), ('bb', (float, 2))])])
      >>> rfn.rename_fields(a, {'a':'A', 'bb':'BB'})
      array([(1, (2., [ 3., 30.])), (4, (5., [ 6., 60.]))],
            dtype=[('A', '<i8'), ('b', [('ba', '<f8'), ('BB', '<f8', (2,))])])
  
      """
  
      def _recursive_rename_fields(ndtype, namemapper):
          newdtype = []
          for name in ndtype.names:
              newname = namemapper.get(name, name)
              current = ndtype[name]
              if current.names is not None:
                  newdtype.append(
                      (
                          newname,
                          _recursive_rename_fields(current, namemapper),
                      )
                  )
              else:
                  newdtype.append((newname, current))
          return newdtype
  
      newdtype = _recursive_rename_fields(base.dtype, namemapper)
      return base.view(newdtype)
  
imports: import itertools
  import numpy
  import numpy.ma
  from numpy import ndarray, recarray
  from numpy.ma import MaskedArray
  from numpy.ma.mrecords import MaskedRecords
  from numpy.core.overrides import array_function_dispatch
  from numpy.lib._iotools import _is_string_like
label_desc: Use image node_id 23 for calling a global function with example usage: rename_fields(base, namemapper) and returns: base, newdtype