(action_spec)
return action
Generates an action to apply to the environment if there is no agent.

  * For action dimensions that are closed intervals this will be the midpoint.
  * For left-open or right-open intervals this will be the maximum or the
    minimum respectively.
  * For unbounded intervals this will be zero.

  Args:
    action_spec: An instance of `BoundedArraySpec` or a list or tuple
      containing these.

  Returns:
    A numpy array of actions if `action_spec` is a single `BoundedArraySpec`, or
    a tuple of such arrays if `action_spec` is a list or tuple.
Generates an action to apply to the environment if there is no agent.
Generates an action to apply to the environment if there is no agent .
def _get_default_action(action_spec):
  """Generates an action to apply to the environment if there is no agent.

  * For action dimensions that are closed intervals this will be the midpoint.
  * For left-open or right-open intervals this will be the maximum or the
    minimum respectively.
  * For unbounded intervals this will be zero.

  Args:
    action_spec: An instance of `BoundedArraySpec` or a list or tuple
      containing these.

  Returns:
    A numpy array of actions if `action_spec` is a single `BoundedArraySpec`, or
    a tuple of such arrays if `action_spec` is a list or tuple.
  """
  if isinstance(action_spec, (list, tuple)):
    return tuple(_get_default_action(spec) for spec in action_spec)
  elif isinstance(action_spec, collections.abc.MutableMapping):
    # Clones the Mapping, preserving type and key order.
    result = copy.copy(action_spec)

    for key, value in action_spec.items():
      result[key] = _get_default_action(value)

    return result

  minimum = np.broadcast_to(action_spec.minimum, action_spec.shape)
  maximum = np.broadcast_to(action_spec.maximum, action_spec.shape)
  left_bounded = np.isfinite(minimum)
  right_bounded = np.isfinite(maximum)
  action = np.select(
      condlist=[left_bounded & right_bounded, left_bounded, right_bounded],
      choicelist=[0.5 * (minimum + maximum), minimum, maximum],
      default=0.)
  action = action.astype(action_spec.dtype, copy=False)
  action.flags.writeable = False
  return action
def _get_default_action ( action_spec ) : if isinstance ( action_spec , ( list , tuple ) ) : return tuple ( _get_default_action ( spec ) for spec in action_spec ) elif isinstance ( action_spec , collections . abc . MutableMapping ) : # Clones the Mapping, preserving type and key order. result = copy . copy ( action_spec ) for key , value in action_spec . items ( ) : result [ key ] = _get_default_action ( value ) return result minimum = np . broadcast_to ( action_spec . minimum , action_spec . shape ) maximum = np . broadcast_to ( action_spec . maximum , action_spec . shape ) left_bounded = np . isfinite ( minimum ) right_bounded = np . isfinite ( maximum ) action = np . select ( condlist = [ left_bounded & right_bounded , left_bounded , right_bounded ] , choicelist = [ 0.5 * ( minimum + maximum ) , minimum , maximum ] , default = 0. ) action = action . astype ( action_spec . dtype , copy = False ) action . flags . writeable = False return action