code: def _scale_nested_action(
      nested_action: types.NestedArray,
      nested_spec: types.NestedSpec,
      clip: bool,
  ) -> types.NestedArray:
      """Converts a canonical nested action back to the given nested action spec."""
  
      def _scale_action(action: np.ndarray, spec: specs.Array):
          """Converts a single canonical action back to the given action spec."""
          if isinstance(spec, specs.BoundedArray):
              # Get scale and offset of output action spec.
              scale = spec.maximum - spec.minimum
              offset = spec.minimum
  
              # Maybe clip the action.
              if clip:
                  action = np.clip(action, -1.0, 1.0)
  
              # Map action to [0, 1].
              action = 0.5 * (action + 1.0)
  
              # Map action to [spec.minimum, spec.maximum].
              action *= scale
              action += offset
  
          return action
  
      return tree.map_structure(
          _scale_action, nested_action, nested_spec
      )
  
file_path: acme/acme/wrappers/canonical_spec.py
imports: from acme import specs
  from acme import types
  from acme.wrappers import base
  import dm_env
  import numpy
  import tree
label_desc: Use image node_id 2 for calling a global function with example usage: _scale_nested_action(nested_action, nested_spec, clip) and returns: tree, action