code: def map_alleles(self, mapping, copy=True):
          
  
          # check inputs
          mapping = asarray_ndim(mapping, 2)
          check_dim0_aligned(self, mapping)
  
          # use optimisation
          mapping = np.asarray(mapping, dtype=self.dtype)
          mapping = memoryview_safe(mapping)
          values = memoryview_safe(self.values)
          data = haplotype_array_map_alleles(values, mapping, copy=copy)
  
          return HaplotypeArray(data, copy=False)
docs: Transform alleles via a mapping.
  
          Parameters
          ----------
          mapping : ndarray, int8, shape (n_variants, max_allele)
              An array defining the allele mapping for each variant.
          copy : bool, optional
              If True, return a new array; if False, apply mapping in place
              (only applies for arrays with dtype int8; all other dtypes
              require a copy).
  
          Returns
          -------
          hm : HaplotypeArray
  
          Examples
          --------
          >>> import allel
          >>> import numpy as np
          >>> h = allel.HaplotypeArray([[0, 0, 0, 1],
          ...                           [0, 1, 1, 1],
          ...                           [0, 2, -1, -1]], dtype='i1')
          >>> mapping = np.array([[1, 2, 0],
          ...                     [2, 0, 1],
          ...                     [2, 1, 0]], dtype='i1')
          >>> h.map_alleles(mapping)
          <HaplotypeArray shape=(3, 4) dtype=int8>
          1 1 1 2
          2 0 0 0
          2 0 . .
  
          Notes
          -----
          For arrays with dtype int8 an optimised implementation is used which is
          faster and uses far less memory. It is recommended to convert arrays to
          dtype int8 where possible before calling this method.
  
          See Also
          --------
          allel.model.util.create_allele_mapping