code: def _convert_pyjags_dict_to_arviz_dict(
      samples: tp.Mapping[str, np.ndarray],
      variable_names: tp.Optional[tp.Tuple[str, ...]] = None,
  ) -> tp.Mapping[str, np.ndarray]:
      """
      Convert a PyJAGS dictionary to an ArviZ dictionary.
  
      Takes a python dictionary of samples that has been generated by the sample
      method of a model instance and returns a dictionary of samples in ArviZ
      format.
  
      Parameters
      ----------
      samples: a dictionary mapping variable names to P arrays with shape
               (parameter_dimension, chain_length, number_of_chains)
  
      Returns
      -------
      a dictionary mapping variable names to NumPy arrays with shape
               (number_of_chains, chain_length, parameter_dimension)
      """
      # pyjags returns a dictionary of NumPy arrays with shape
      #         (parameter_dimension, chain_length, number_of_chains)
      # but arviz expects samples with shape
      #         (number_of_chains, chain_length, parameter_dimension)
  
      variable_name_to_samples_map = {}
  
      if variable_names is None:
          variable_names = tuple(samples.keys())
  
      for variable_name, chains in samples.items():
          if variable_name in variable_names:
              parameter_dimension, _, _ = chains.shape
              if parameter_dimension == 1:
                  variable_name_to_samples_map[variable_name] = chains[
                      0, :, :
                  ].transpose()
              else:
                  variable_name_to_samples_map[
                      variable_name
                  ] = np.swapaxes(chains, 0, 2)
  
      return variable_name_to_samples_map
  
imports: import typing
  from collections import OrderedDict
  from collections.abc import Iterable
  import numpy
  import xarray
  from .inference_data import InferenceData
  from ..rcparams import rcParams
  from .base import dict_to_dataset
label_desc: Use image node_id 3 for calling a global function with example usage: _convert_pyjags_dict_to_arviz_dict(samples, variable_names) and returns: variable_name_to_samples_map