tf.dtypes.DType
Stay organized with collections
Save and categorize content based on your preferences.
Represents the type of the elements in a Tensor
.
Inherits From: TraceType
tf.dtypes.DType()
DType
's are used to specify the output data type for operations which
require it, or to inspect the data type of existing Tensor
's.
Examples:
tf.constant(1, dtype=tf.int64)
<tf.Tensor: shape=(), dtype=int64, numpy=1>
tf.constant(1.0).dtype
tf.float32
See tf.dtypes
for a complete list of DType
's defined.
Attributes |
as_datatype_enum
|
Returns a types_pb2.DataType enum value based on this data type.
|
as_numpy_dtype
|
Returns a Python type object based on this DType .
|
base_dtype
|
Returns a non-reference DType based on this DType .
|
is_bool
|
Returns whether this is a boolean data type.
|
is_complex
|
Returns whether this is a complex floating point type.
|
is_floating
|
Returns whether this is a (non-quantized, real) floating point type.
|
is_integer
|
Returns whether this is a (non-quantized) integer type.
|
is_numpy_compatible
|
Returns whether this data type has a compatible NumPy data type.
|
is_quantized
|
Returns whether this is a quantized data type.
|
is_unsigned
|
Returns whether this type is unsigned.
Non-numeric, unordered, and quantized types are not considered unsigned, and
this function returns False .
|
limits
|
Return intensity limits, i.e.
(min, max) tuple, of the dtype.
Args:
clip_negative : bool, optional If True, clip the negative range (i.e.
return 0 for min intensity) even if the image dtype allows negative
values. Returns
min, max : tuple Lower and upper intensity limits.
|
max
|
Returns the maximum representable value in this data type.
|
min
|
Returns the minimum representable value in this data type.
|
name
|
|
real_dtype
|
Returns the DType corresponding to this DType 's real part.
|
size
|
|
Methods
experimental_as_proto
View source
experimental_as_proto() -> types_pb2.SerializedDType
Returns a proto representation of the Dtype instance.
experimental_from_proto
View source
@classmethod
experimental_from_proto(
proto: types_pb2.SerializedDType
) -> 'DType'
Returns a Dtype instance based on the serialized proto.
experimental_type_proto
View source
@classmethod
experimental_type_proto() -> Type[types_pb2.SerializedDType]
Returns the type of proto associated with DType serialization.
is_compatible_with
View source
is_compatible_with(
other
)
Returns True if the other
DType will be converted to this DType.
The conversion rules are as follows:
DType(T) .is_compatible_with(DType(T)) == True
Args |
other
|
A DType (or object that may be converted to a DType ).
|
Returns |
True if a Tensor of the other DType will be implicitly converted to
this DType .
|
is_subtype_of
View source
is_subtype_of(
other: tf.types.experimental.TraceType
) -> bool
See tf.types.experimental.TraceType base class.
most_specific_common_supertype
View source
most_specific_common_supertype(
types: Sequence[tf.types.experimental.TraceType
]
) -> Optional['DType']
See tf.types.experimental.TraceType base class.
__eq__
View source
__eq__(
other
)
Returns True iff this DType refers to the same type as other
.
__ne__
View source
__ne__(
other
)
Returns True iff self != other.
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. Some content is licensed under the numpy license.
Last updated 2023-03-17 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-03-17 UTC."],[],[],null,["# tf.dtypes.DType\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.10.1/tensorflow/python/framework/dtypes.py#L41-L239) |\n\nRepresents the type of the elements in a `Tensor`.\n\nInherits From: [`TraceType`](../../tf/types/experimental/TraceType)\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tf.DType`](https://www.tensorflow.org/api_docs/python/tf/dtypes/DType)\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.DType`](https://www.tensorflow.org/api_docs/python/tf/dtypes/DType), [`tf.compat.v1.dtypes.DType`](https://www.tensorflow.org/api_docs/python/tf/dtypes/DType)\n\n\u003cbr /\u003e\n\n tf.dtypes.DType()\n\n`DType`'s are used to specify the output data type for operations which\nrequire it, or to inspect the data type of existing `Tensor`'s.\n\n#### Examples:\n\n tf.constant(1, dtype=tf.int64)\n \u003ctf.Tensor: shape=(), dtype=int64, numpy=1\u003e\n tf.constant(1.0).dtype\n tf.float32\n\nSee [`tf.dtypes`](../../tf/dtypes) for a complete list of `DType`'s defined.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `as_datatype_enum` | Returns a `types_pb2.DataType` enum value based on this data type. |\n| `as_numpy_dtype` | Returns a Python `type` object based on this `DType`. |\n| `base_dtype` | Returns a non-reference `DType` based on this `DType`. |\n| `is_bool` | Returns whether this is a boolean data type. |\n| `is_complex` | Returns whether this is a complex floating point type. |\n| `is_floating` | Returns whether this is a (non-quantized, real) floating point type. |\n| `is_integer` | Returns whether this is a (non-quantized) integer type. |\n| `is_numpy_compatible` | Returns whether this data type has a compatible NumPy data type. |\n| `is_quantized` | Returns whether this is a quantized data type. |\n| `is_unsigned` | Returns whether this type is unsigned. \u003cbr /\u003e Non-numeric, unordered, and quantized types are not considered unsigned, and this function returns `False`. |\n| `limits` | Return intensity limits, i.e. \u003cbr /\u003e (min, max) tuple, of the dtype. Args: clip_negative : bool, optional If True, clip the negative range (i.e. return 0 for min intensity) even if the image dtype allows negative values. Returns min, max : tuple Lower and upper intensity limits. |\n| `max` | Returns the maximum representable value in this data type. |\n| `min` | Returns the minimum representable value in this data type. |\n| `name` | \u003cbr /\u003e \u003cbr /\u003e |\n| `real_dtype` | Returns the `DType` corresponding to this `DType`'s real part. |\n| `size` | \u003cbr /\u003e \u003cbr /\u003e |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `experimental_as_proto`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.10.1/tensorflow/python/framework/dtypes.py#L211-L213) \n\n experimental_as_proto() -\u003e types_pb2.SerializedDType\n\nReturns a proto representation of the Dtype instance.\n\n### `experimental_from_proto`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.10.1/tensorflow/python/framework/dtypes.py#L206-L209) \n\n @classmethod\n experimental_from_proto(\n proto: types_pb2.SerializedDType\n ) -\u003e 'DType'\n\nReturns a Dtype instance based on the serialized proto.\n\n### `experimental_type_proto`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.10.1/tensorflow/python/framework/dtypes.py#L201-L204) \n\n @classmethod\n experimental_type_proto() -\u003e Type[types_pb2.SerializedDType]\n\nReturns the type of proto associated with DType serialization.\n\n### `is_compatible_with`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.10.1/tensorflow/python/framework/dtypes.py#L172-L190) \n\n is_compatible_with(\n other\n )\n\nReturns True if the `other` DType will be converted to this DType.\n\nThe conversion rules are as follows: \n\n DType(T) .is_compatible_with(DType(T)) == True\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|---------|-----------------------------------------------------------|\n| `other` | A `DType` (or object that may be converted to a `DType`). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| True if a Tensor of the `other` `DType` will be implicitly converted to this `DType`. ||\n\n\u003cbr /\u003e\n\n### `is_subtype_of`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.10.1/tensorflow/python/framework/dtypes.py#L192-L194) \n\n is_subtype_of(\n other: ../../tf/types/experimental/TraceType\n ) -\u003e bool\n\nSee tf.types.experimental.TraceType base class.\n\n### `most_specific_common_supertype`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.10.1/tensorflow/python/framework/dtypes.py#L196-L199) \n\n most_specific_common_supertype(\n types: Sequence[../../tf/types/experimental/TraceType]\n ) -\u003e Optional['DType']\n\nSee tf.types.experimental.TraceType base class.\n\n### `__eq__`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.10.1/tensorflow/python/framework/dtypes.py#L215-L226) \n\n __eq__(\n other\n )\n\nReturns True iff this DType refers to the same type as `other`.\n\n### `__ne__`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.10.1/tensorflow/python/framework/dtypes.py#L228-L230) \n\n __ne__(\n other\n )\n\nReturns True iff self != other."]]