code: def params_broadcast_shapes(
      param_shapes, ndims_params, use_pytensor=True
  ):
      """Broadcast parameters that have different dimensions.
  
      Parameters
      ==========
      param_shapes : list of ndarray or Variable
          The shapes of each parameters to broadcast.
      ndims_params : list of int
          The expected number of dimensions for each element in `params`.
      use_pytensor : bool
          If ``True``, use PyTensor `Op`; otherwise, use NumPy.
  
      Returns
      =======
      bcast_shapes : list of ndarray
          The broadcasted values of `params`.
      """
      max_fn = maximum if use_pytensor else max
  
      rev_extra_dims = []
      for ndim_param, param_shape in zip(ndims_params, param_shapes):
          # We need this in order to use `len`
          param_shape = tuple(param_shape)
          extras = tuple(param_shape[: (len(param_shape) - ndim_param)])
  
          def max_bcast(x, y):
              if getattr(x, "value", x) == 1:
                  return y
              if getattr(y, "value", y) == 1:
                  return x
              return max_fn(x, y)
  
          rev_extra_dims = [
              max_bcast(a, b)
              for a, b in zip_longest(
                  reversed(extras), rev_extra_dims, fillvalue=1
              )
          ]
  
      extra_dims = tuple(reversed(rev_extra_dims))
  
      bcast_shapes = [
          (extra_dims + tuple(param_shape)[-ndim_param:])
          if ndim_param > 0
          else extra_dims
          for ndim_param, param_shape in zip(ndims_params, param_shapes)
      ]
  
      return bcast_shapes
  
imports: from collections.abc import Sequence
  from functools import wraps
  from itertools import zip_longest
  from types import ModuleType
  from typing import TYPE_CHECKING, Literal, Optional, Union
  import numpy
  from pytensor.compile.sharedvalue import shared
  from pytensor.graph.basic import Constant, Variable
  from pytensor.scalar import ScalarVariable
  from pytensor.tensor import get_vector_length
  from pytensor.tensor.basic import as_tensor_variable, cast, constant
  from pytensor.tensor.extra_ops import broadcast_to
  from pytensor.tensor.math import maximum
  from pytensor.tensor.shape import specify_shape
  from pytensor.tensor.type import int_dtypes
  from pytensor.tensor.variable import TensorVariable
label_desc: Use image node_id 1 for calling a global function with example usage: params_broadcast_shapes(param_shapes, ndims_params, use_pytensor) and returns: bcast_shapes, max_fn, y, x