code: def create_param(spec, shape, name=None):
      """
      Helper method to create Theano shared variables for layer parameters
      and to initialize them.
  
      Parameters
      ----------
      spec : scalar number, numpy array, Theano expression, or callable
          Either of the following:
  
          * a scalar or a numpy array with the initial parameter values
          * a Theano expression or shared variable representing the parameters
          * a function or callable that takes the desired shape of
            the parameter array as its single argument and returns
            a numpy array, a Theano expression, or a shared variable
            representing the parameters.
  
      shape : iterable of int
          a tuple or other iterable of integers representing the desired
          shape of the parameter array.
  
      name : string, optional
          The name to give to the parameter variable. Ignored if `spec`
          is or returns a Theano expression or shared variable that
          already has a name.
  
  
      Returns
      -------
      Theano shared variable or Theano expression
          A Theano shared variable or expression representing layer parameters.
          If a scalar or a numpy array was provided, a shared variable is
          initialized to contain this array. If a shared variable or expression
          was provided, it is simply returned. If a callable was provided, it is
          called, and its output is used to initialize a shared variable.
  
      Notes
      -----
      This function is called by :meth:`Layer.add_param()` in the constructor
      of most :class:`Layer` subclasses. This enables those layers to
      support initialization with scalars, numpy arrays, existing Theano shared
      variables or expressions, and callables for generating initial parameter
      values, Theano expressions, or shared variables.
      """
      import numbers  # to check if argument is a number
  
      shape = tuple(shape)  # convert to tuple if needed
      if any(d <= 0 for d in shape):
          raise ValueError(
              (
                  "Cannot create param with a non-positive shape dimension. "
                  "Tried to create param with shape=%r, name=%r"
              )
              % (shape, name)
          )
  
      err_prefix = "cannot initialize parameter %s: " % name
      if callable(spec):
          spec = spec(shape)
          err_prefix += "the %s returned by the provided callable"
      else:
          err_prefix += "the provided %s"
  
      if (
          isinstance(spec, numbers.Number)
          or isinstance(spec, np.generic)
          and spec.dtype.kind in "biufc"
      ):
          spec = np.asarray(spec)
  
      if isinstance(spec, np.ndarray):
          if spec.shape != shape:
              raise ValueError(
                  "%s has shape %s, should be %s"
                  % (err_prefix % "numpy array", spec.shape, shape)
              )
          # We assume parameter variables do not change shape after creation.
          # We can thus fix their broadcast pattern, to allow Theano to infer
          # broadcastable dimensions of expressions involving these parameters.
          bcast = tuple(s == 1 for s in shape)
          spec = theano.shared(spec, broadcastable=bcast)
  
      if isinstance(spec, theano.Variable):
          # We cannot check the shape here, Theano expressions (even shared
          # variables) do not have a fixed compile-time shape. We can check the
          # dimensionality though.
          if spec.ndim != len(shape):
              raise ValueError(
                  "%s has %d dimensions, should be %d"
                  % (
                      err_prefix % "Theano variable",
                      spec.ndim,
                      len(shape),
                  )
              )
          # We only assign a name if the user hasn't done so already.
          if not spec.name:
              spec.name = name
          return spec
  
      else:
          if "callable" in err_prefix:
              raise TypeError(
                  "%s is not a numpy array or a Theano expression"
                  % (err_prefix % "value")
              )
          else:
              raise TypeError(
                  "%s is not a numpy array, a Theano expression, "
                  "or a callable" % (err_prefix % "spec")
              )
  
file_path: Lasagne/lasagne/utils.py
imports: import numbers
  import numpy
  import theano
  import theano.tensor
label_desc: Use image node_id 10 for calling a global function with example usage: create_param(spec, shape, name) and returns: spec