tf_agents.specs.ArraySpec
Stay organized with collections
Save and categorize content based on your preferences.
Describes a numpy array or scalar shape and dtype.
tf_agents.specs.ArraySpec(
shape, dtype, name=None
)
An ArraySpec
allows an API to describe the arrays that it accepts or
returns, before that array exists.
The equivalent version describing a tf.Tensor
is TensorSpec
.
Args |
shape
|
An iterable specifying the array shape.
|
dtype
|
numpy dtype or string specifying the array dtype.
|
name
|
Optional string containing a semantic name for the corresponding
array. Defaults to None .
|
Raises |
TypeError
|
If the shape is not an iterable or if the dtype is an invalid
numpy dtype.
|
Attributes |
dtype
|
Returns a numpy dtype specifying the array dtype.
|
name
|
Returns the name of the ArraySpec.
|
shape
|
Returns a tuple specifying the array shape.
|
Methods
check_array
View source
check_array(
array
)
Return whether the given NumPy array conforms to the spec.
Args |
array
|
A NumPy array or a scalar. Tuples and lists will not be converted
to a NumPy array automatically; they will cause this function to return
false, even if a conversion to a conforming array is trivial.
|
Returns |
True if the array conforms to the spec, False otherwise.
|
from_array
View source
@staticmethod
from_array(
array, name=None
)
Construct a spec from the given array or number.
from_spec
View source
@staticmethod
from_spec(
spec
)
Construct a spec from the given spec.
replace
View source
replace(
shape=None, dtype=None, name=None
)
__eq__
View source
__eq__(
other
)
Checks if the shape and dtype of two specs are equal.
__ne__
View source
__ne__(
other
)
Return self!=value.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-04-26 UTC.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf_agents.specs.ArraySpec\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/specs/array_spec.py#L169-L267) |\n\nDescribes a numpy array or scalar shape and dtype.\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tf_agents.specs.array_spec.ArraySpec`](https://www.tensorflow.org/agents/api_docs/python/tf_agents/specs/ArraySpec)\n\n\u003cbr /\u003e\n\n tf_agents.specs.ArraySpec(\n shape, dtype, name=None\n )\n\nAn `ArraySpec` allows an API to describe the arrays that it accepts or\nreturns, before that array exists.\nThe equivalent version describing a [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) is `TensorSpec`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------|---------------------------------------------------------------------------------------------|\n| `shape` | An iterable specifying the array shape. |\n| `dtype` | numpy dtype or string specifying the array dtype. |\n| `name` | Optional string containing a semantic name for the corresponding array. Defaults to `None`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|-------------|------------------------------------------------------------------------------|\n| `TypeError` | If the shape is not an iterable or if the `dtype` is an invalid numpy dtype. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|---------|---------------------------------------------------|\n| `dtype` | Returns a numpy dtype specifying the array dtype. |\n| `name` | Returns the name of the ArraySpec. |\n| `shape` | Returns a `tuple` specifying the array shape. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `check_array`\n\n[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/specs/array_spec.py#L227-L243) \n\n check_array(\n array\n )\n\nReturn whether the given NumPy array conforms to the spec.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `array` | A NumPy array or a scalar. Tuples and lists will not be converted to a NumPy array automatically; they will cause this function to return false, even if a conversion to a conforming array is trivial. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| True if the array conforms to the spec, False otherwise. ||\n\n\u003cbr /\u003e\n\n### `from_array`\n\n[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/specs/array_spec.py#L248-L256) \n\n @staticmethod\n from_array(\n array, name=None\n )\n\nConstruct a spec from the given array or number.\n\n### `from_spec`\n\n[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/specs/array_spec.py#L258-L261) \n\n @staticmethod\n from_spec(\n spec\n )\n\nConstruct a spec from the given spec.\n\n### `replace`\n\n[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/specs/array_spec.py#L263-L267) \n\n replace(\n shape=None, dtype=None, name=None\n )\n\n### `__eq__`\n\n[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/specs/array_spec.py#L218-L222) \n\n __eq__(\n other\n )\n\nChecks if the shape and dtype of two specs are equal.\n\n### `__ne__`\n\n[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/specs/array_spec.py#L224-L225) \n\n __ne__(\n other\n )\n\nReturn self!=value."]]