# tf_agents.environments.gym_wrapper.spec_from_gym_space

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/environments/gym_wrapper.py#L37-L150) |

Converts gym spaces into array specs.

    tf_agents.environments.gym_wrapper.spec_from_gym_space(
        space: gym.Space,
        dtype_map: Optional[Dict[gym.Space, np.dtype]] = None,
        simplify_box_bounds: bool = True,
        name: Optional[Text] = None
    ) -> https://www.tensorflow.org/agents/api_docs/python/tf_agents/specs/BoundedArraySpec

Gym does not properly define dtypes for spaces. By default all spaces set
their type to float64 even though observations do not always return this type.
See:
<https://github.com/openai/gym/issues/527>

To handle this we allow a dtype_map for setting default types for mapping
spaces to specs.

observations. Not sure that we have a need for this yet.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `space` | gym.Space to turn into a spec. |
| `dtype_map` | A dict from spaces to dtypes to use as the default dtype. |
| `simplify_box_bounds` | Whether to replace bounds of Box space that are arrays with identical values with one number and rely on broadcasting. |
| `name` | Name of the spec. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A BoundedArraySpec nest mirroring the given space structure. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If there is an unknown space type. |

<br />