Table of Contents

Class Space<T>

Namespace
Gym.Spaces
Assembly
Gym.dll

A space whose elements are T: Box and Discrete are Space<NDArray> (a discrete element is a 0-d int64 array, NumPy's np.int64, DR-08). An env's ActionSpace and ObservationSpace are typed this way (DR-07), and custom spaces derive from it.

public abstract class Space<T> : Space, IDisposable

Type Parameters

T

The element type, what Sample(object?, object?) returns.

Inheritance
Space<T>
Implements
Derived
Inherited Members
Extension Methods

Remarks

Constructors

Space(Shape?, DType?, SpaceSeed?)

Records the shape and dtype and seeds the generator when a seed is given.

protected Space(Shape? shape, DType? dtype, SpaceSeed? seed)

Parameters

shape Shape?

The shape of every element, or null when elements are not arrays.

dtype DType

The element dtype, or null when elements are not arrays.

seed SpaceSeed?

An integer seed, a generator to share, or null for a lazy entropy-seeded one.

Exceptions

Error

Thrown when an integer seed is negative.

Methods

FromJsonable(object)

Converts JSON-friendly data back to samples (Gymnasium's from_jsonable); the default casts each item. It hides the untyped FromJsonable(object), which returns the same samples boxed.

public virtual IList<T> FromJsonable(object jsonable)

Parameters

jsonable object

The data, a list for the default.

Returns

IList<T>

The samples.

Exceptions

ArgumentException

Thrown by the default when the data is not a list.

InvalidCastException

Thrown by the default when an item is not a T.

JsonList(object)

JSON-friendly data as the list a space's from_jsonable iterates over.

protected static IList<object?> JsonList(object jsonable)

Parameters

jsonable object

The data.

Returns

IList<object>

Its items.

Exceptions

ArgumentException

Thrown when the data is not a list.

Sample(object?, object?)

Draws a random element (Gymnasium's sample). A mask restricts which elements are drawn and a probability mask weights them; the two cannot be combined, and each space documents the forms it accepts.

public abstract T Sample(object? mask = null, object? probability = null)

Parameters

mask object

A space-specific mask, or null.

probability object

A space-specific probability mask, or null.

Returns

T

The element; arrays are new and owned by the caller.

ToJsonable(IEnumerable<T>)

Converts a batch of samples to JSON-friendly data (Gymnasium's to_jsonable); the default keeps them as they are, in a list, as Gymnasium's base does.

public virtual object ToJsonable(IEnumerable<T> samples)

Parameters

samples IEnumerable<T>

The samples.

Returns

object

The JSON-friendly data; a list of one value per sample unless the space documents another form.