Table of Contents

Class DtypeObservation<TObs, TAct>

Namespace
Gym.Wrappers
Assembly
Gym.dll

Converts every observation to a dtype, as Gymnasium's DtypeObservation does: a Box, MultiDiscrete or MultiBinary observation keeps its shape, a Discrete one becomes a 0-d array of the dtype (a NumPy scalar), and the space follows.

public class DtypeObservation<TObs, TAct> : TransformObservation<NDArray, TObs, TAct>, IDynamicAttributes, IWrapper, IEnv, IDisposable, IRecordConstructorArgs

Type Parameters

TObs

The env's observation type: arrays or numbers (NDArray, or object).

TAct

The action type, passed through.

Inheritance
Env<NDArray, TAct>
Wrapper<NDArray, TAct, TObs, TAct>
DtypeObservation<TObs, TAct>
Implements
Inherited Members
Extension Methods

Remarks

The conversion is NumPy's dtype.type(obs), an unsafe cast: float to integer truncates, and out-of-range values wrap. A Discrete(n, start) space becomes Box(start, start + n - 1, (), dtype), a MultiBinary one Box(0, 1, shape, dtype), a MultiDiscrete one keeps its nvec and start.

Reference: gymnasium/wrappers/transform_observation.py.

Constructors

DtypeObservation(Env<TObs, TAct>, DtypeObservationOptions)

Builds the instance from its options record: the properties set, the constructor's defaults for the rest.

public DtypeObservation(Env<TObs, TAct> env, DtypeObservationOptions options)

Parameters

env Env<TObs, TAct>

The env to wrap.

options DtypeObservationOptions

The options.

Exceptions

ArgumentNullException

Thrown when options is null.

TypeError

Thrown when a required argument is unset, with Python's missing-argument message.

DtypeObservation(Env<TObs, TAct>, object)

Wraps env.

public DtypeObservation(Env<TObs, TAct> env, object dtype)

Parameters

env Env<TObs, TAct>

The env; its observation space must be a Box, Discrete, MultiDiscrete or MultiBinary.

dtype object

The dtype: a DType (np.float32), its name ("float32"), an NPTypeCode or a .NET Type.

Exceptions

TypeError

Thrown when the space is of another kind (Gymnasium's message), the dtype cannot be read, or env is null.

Properties

Dtype

The dtype as given (dtype).

public object Dtype { get; }

Property Value

object