code: def expand_array(x, ndim):
      """Add dimensions to an array to match the number of desired dimensions
  
      If x.ndim < ndim, it adds ndim - x.ndim dimensions after the last axis. If not, it is left
      untouched.
  
      For example, if we have a normal regression model with n = 1000, chains = 2, and draws = 500
      the shape of the draws of mu will be (2, 500, 1000) but the shape of the draws of sigma will be
      (2, 500). This function makes sure the shape of the draws of sigma is (2, 500, 1) which is
      comaptible with (2, 500, 1000).
  
      Parameters
      ----------
      x : np.ndarray
          The array
      ndim : int
          The number of desired dimensions
  
      Returns
      -------
      np.ndarray
          The array with the expanded dimensions
      """
      if x.ndim == ndim:
          return x
      dims_to_expand = tuple(range(ndim - 1, x.ndim - 1, -1))
      return np.expand_dims(x, dims_to_expand)
  
file_path: bambi/bambi/families/family.py
imports: from typing import Dict, Union
  import numpy
  import pymc
  import xarray
  from bambi.families.link import Link
  from bambi.utils import get_auxiliary_parameters, get_aliased_name
label_desc: Use image node_id 2 for calling a global function with example usage: expand_array(x, ndim) and returns: np, x