Type TensorShape
Namespace tensorflow
Parent PythonObjectContainer
Interfaces ITensorShape
Represents the shape of a `Tensor`. A `TensorShape` represents a possibly-partial shape specification for a
`Tensor`. It may be one of the following: * *Fully-known shape:* has a known number of dimensions and a known size
for each dimension. e.g. `TensorShape([16, 256])`
* *Partially-known shape:* has a known number of dimensions, and an unknown
size for one or more dimension. e.g. `TensorShape([None, 256])`
* *Unknown shape:* has an unknown number of dimensions, and an unknown
size in all dimensions. e.g. `TensorShape(None)` If a tensor is produced by an operation of type `"Foo"`, its shape
may be inferred if there is a registered shape function for
`"Foo"`. See [Shape
functions](https://tensorflow.org/extend/adding_an_op#shape_functions_in_c)
for details of shape functions and how to register them. Alternatively,
the shape may be set explicitly using
tf.Tensor.set_shape
.
Methods
- __concat__
- __concat___dyn
- __getitem__
- __getitem__
- __getitem___dyn
- __radd__
- __radd__
- as_list
- as_list_dyn
- as_proto
- as_proto_dyn
- assert_has_rank
- assert_has_rank_dyn
- assert_is_fully_defined
- assert_is_fully_defined_dyn
- assert_same_rank
- assert_same_rank
- assert_same_rank
- assert_same_rank
- assert_same_rank
- assert_same_rank_dyn
- concatenate_dyn
- Get
- GetEnumerator
- is_compatible_with
- is_compatible_with
- is_fully_defined
- is_fully_defined_dyn
- merge_with
- most_specific_compatible_shape
- most_specific_compatible_shape_dyn
- num_elements_dyn
- with_rank
- with_rank
- with_rank_at_least
- with_rank_at_least_dyn
- with_rank_at_most
- with_rank_at_most_dyn
- with_rank_dyn
Properties
Public instance methods
TensorShape __concat__(object other)
object __concat___dyn(object other)
object __getitem__(string key)
Returns the value of a dimension or a shape, depending on the key.
Parameters
-
string
key - If `key` is an integer, returns the dimension at that index; otherwise if `key` is a slice, returns a TensorShape whose dimensions are those selected by the slice from `self`.
Returns
-
object
- An integer if `key` is an integer, or a `TensorShape` if `key` is a slice.
object __getitem__(int key)
Returns the specified piece of this RaggedTensor. Supports multidimensional indexing and slicing, with one restriction:
indexing into a ragged inner dimension is not allowed. This case is
problematic because the indicated value may exist in some rows but not
others. In such cases, it's not obvious whether we should (1) report an
IndexError; (2) use a default value; or (3) skip that value and return a
tensor with fewer rows than we started with. Following the guiding
principles of Python ("In the face of ambiguity, refuse the temptation to
guess"), we simply disallow this operation. Any dimensions added by `array_ops.newaxis` will be ragged if the following
dimension is ragged.
Parameters
-
int
key - Indicates which piece of the RaggedTensor to return, using standard
Python semantics (e.g., negative values index from the end). `key`
may have any of the following types: * `int` constant
* Scalar integer `Tensor`
* `slice` containing integer constants and/or scalar integer
`Tensor`s
* `Ellipsis`
*
tf.newaxis
* `tuple` containing any of the above (for multidimentional indexing)
Returns
-
object
- A `Tensor` or `RaggedTensor` object. Values that include at least one ragged dimension are returned as `RaggedTensor`. Values that include no ragged dimensions are returned as `Tensor`. See above for examples of expressions that return `Tensor`s vs `RaggedTensor`s.
object __getitem___dyn(object key)
Returns the specified piece of this RaggedTensor. Supports multidimensional indexing and slicing, with one restriction:
indexing into a ragged inner dimension is not allowed. This case is
problematic because the indicated value may exist in some rows but not
others. In such cases, it's not obvious whether we should (1) report an
IndexError; (2) use a default value; or (3) skip that value and return a
tensor with fewer rows than we started with. Following the guiding
principles of Python ("In the face of ambiguity, refuse the temptation to
guess"), we simply disallow this operation. Any dimensions added by `array_ops.newaxis` will be ragged if the following
dimension is ragged.
Parameters
-
object
key - Indicates which piece of the RaggedTensor to return, using standard
Python semantics (e.g., negative values index from the end). `key`
may have any of the following types: * `int` constant
* Scalar integer `Tensor`
* `slice` containing integer constants and/or scalar integer
`Tensor`s
* `Ellipsis`
*
tf.newaxis
* `tuple` containing any of the above (for multidimentional indexing)
Returns
-
object
- A `Tensor` or `RaggedTensor` object. Values that include at least one ragged dimension are returned as `RaggedTensor`. Values that include no ragged dimensions are returned as `Tensor`. See above for examples of expressions that return `Tensor`s vs `RaggedTensor`s.
TensorShape __radd__(IGraphNodeBase other)
TensorShape __radd__(int other)
IList<Nullable<int>> as_list()
Returns a list of integers or `None` for each dimension.
Returns
-
IList<Nullable<int>>
- A list of integers or `None` for each dimension.
object as_list_dyn()
Returns a list of integers or `None` for each dimension.
Returns
-
object
- A list of integers or `None` for each dimension.
object as_proto()
Returns this shape as a `TensorShapeProto`.
object as_proto_dyn()
Returns this shape as a `TensorShapeProto`.
void assert_has_rank(Nullable<int> rank)
Raises an exception if `self` is not compatible with the given `rank`.
Parameters
-
Nullable<int>
rank - An integer.
object assert_has_rank_dyn(object rank)
Raises an exception if `self` is not compatible with the given `rank`.
Parameters
-
object
rank - An integer.
void assert_is_fully_defined()
Raises an exception if `self` is not fully defined in every dimension.
object assert_is_fully_defined_dyn()
Raises an exception if `self` is not fully defined in every dimension.
void assert_same_rank(TensorShape other)
Raises an exception if `self` and `other` do not have compatible ranks.
Parameters
-
TensorShape
other - Another `TensorShape`.
void assert_same_rank(int other)
Raises an exception if `self` and `other` do not have compatible ranks.
Parameters
-
int
other - Another `TensorShape`.
void assert_same_rank(Dimension other)
Raises an exception if `self` and `other` do not have compatible ranks.
Parameters
-
Dimension
other - Another `TensorShape`.
void assert_same_rank(IEnumerable<int> other)
Raises an exception if `self` and `other` do not have compatible ranks.
Parameters
-
IEnumerable<int>
other - Another `TensorShape`.
void assert_same_rank(IGraphNodeBase other)
Raises an exception if `self` and `other` do not have compatible ranks.
Parameters
-
IGraphNodeBase
other - Another `TensorShape`.
object assert_same_rank_dyn(object other)
Raises an exception if `self` and `other` do not have compatible ranks.
Parameters
-
object
other - Another `TensorShape`.
object concatenate_dyn(object other)
Returns the concatenation of the dimension in `self` and `other`. *N.B.* If either `self` or `other` is completely unknown,
concatenation will discard information about the other shape. In
future, we might support concatenation that preserves this
information for use with slicing.
Parameters
-
object
other - Another `TensorShape`.
Returns
-
object
- A `TensorShape` whose dimensions are the concatenation of the dimensions in `self` and `other`.
IEnumerator GetEnumerator()
Returns enumerator for this list
bool is_compatible_with(ValueTuple<IEnumerable<object>, object> other)
Returns True iff `self` is compatible with `other`. Two possibly-partially-defined shapes are compatible if there
exists a fully-defined shape that both shapes can represent. Thus,
compatibility allows the shape inference code to reason about
partially-defined shapes. For example: * TensorShape(None) is compatible with all shapes. * TensorShape([None, None]) is compatible with all two-dimensional
shapes, such as TensorShape([32, 784]), and also TensorShape(None). It is
not compatible with, for example, TensorShape([None]) or
TensorShape([None, None, None]). * TensorShape([32, None]) is compatible with all two-dimensional shapes
with size 32 in the 0th dimension, and also TensorShape([None, None])
and TensorShape(None). It is not compatible with, for example,
TensorShape([32]), TensorShape([32, None, 1]) or TensorShape([64, None]). * TensorShape([32, 784]) is compatible with itself, and also
TensorShape([32, None]), TensorShape([None, 784]), TensorShape([None,
None]) and TensorShape(None). It is not compatible with, for example,
TensorShape([32, 1, 784]) or TensorShape([None]). The compatibility relation is reflexive and symmetric, but not
transitive. For example, TensorShape([32, 784]) is compatible with
TensorShape(None), and TensorShape(None) is compatible with
TensorShape([4, 4]), but TensorShape([32, 784]) is not compatible with
TensorShape([4, 4]).
Parameters
-
ValueTuple<IEnumerable<object>, object>
other - Another TensorShape.
Returns
-
bool
- True iff `self` is compatible with `other`.
bool is_compatible_with(ndarray other)
Returns True iff `self` is compatible with `other`. Two possibly-partially-defined shapes are compatible if there
exists a fully-defined shape that both shapes can represent. Thus,
compatibility allows the shape inference code to reason about
partially-defined shapes. For example: * TensorShape(None) is compatible with all shapes. * TensorShape([None, None]) is compatible with all two-dimensional
shapes, such as TensorShape([32, 784]), and also TensorShape(None). It is
not compatible with, for example, TensorShape([None]) or
TensorShape([None, None, None]). * TensorShape([32, None]) is compatible with all two-dimensional shapes
with size 32 in the 0th dimension, and also TensorShape([None, None])
and TensorShape(None). It is not compatible with, for example,
TensorShape([32]), TensorShape([32, None, 1]) or TensorShape([64, None]). * TensorShape([32, 784]) is compatible with itself, and also
TensorShape([32, None]), TensorShape([None, 784]), TensorShape([None,
None]) and TensorShape(None). It is not compatible with, for example,
TensorShape([32, 1, 784]) or TensorShape([None]). The compatibility relation is reflexive and symmetric, but not
transitive. For example, TensorShape([32, 784]) is compatible with
TensorShape(None), and TensorShape(None) is compatible with
TensorShape([4, 4]), but TensorShape([32, 784]) is not compatible with
TensorShape([4, 4]).
Parameters
-
ndarray
other - Another TensorShape.
Returns
-
bool
- True iff `self` is compatible with `other`.
bool is_fully_defined()
Returns True iff `self` is fully defined in every dimension.
object is_fully_defined_dyn()
Returns True iff `self` is fully defined in every dimension.
object merge_with(IGraphNodeBase other)
Returns a `TensorShape` combining the information in `self` and `other`. The dimensions in `self` and `other` are merged elementwise,
according to the rules defined for `Dimension.merge_with()`.
Parameters
-
IGraphNodeBase
other - Another `TensorShape`.
Returns
-
object
- A `TensorShape` containing the combined information of `self` and `other`.
TensorShape most_specific_compatible_shape(TensorShape other)
Returns the most specific TensorShape compatible with `self` and `other`. * TensorShape([None, 1]) is the most specific TensorShape compatible with
both TensorShape([2, 1]) and TensorShape([5, 1]). Note that
TensorShape(None) is also compatible with above mentioned TensorShapes. * TensorShape([1, 2, 3]) is the most specific TensorShape compatible with
both TensorShape([1, 2, 3]) and TensorShape([1, 2, 3]). There are more
less specific TensorShapes compatible with above mentioned TensorShapes,
e.g. TensorShape([1, 2, None]), TensorShape(None).
Parameters
-
TensorShape
other - Another `TensorShape`.
Returns
-
TensorShape
- A `TensorShape` which is the most specific compatible shape of `self` and `other`.
object most_specific_compatible_shape_dyn(object other)
Returns the most specific TensorShape compatible with `self` and `other`. * TensorShape([None, 1]) is the most specific TensorShape compatible with
both TensorShape([2, 1]) and TensorShape([5, 1]). Note that
TensorShape(None) is also compatible with above mentioned TensorShapes. * TensorShape([1, 2, 3]) is the most specific TensorShape compatible with
both TensorShape([1, 2, 3]) and TensorShape([1, 2, 3]). There are more
less specific TensorShapes compatible with above mentioned TensorShapes,
e.g. TensorShape([1, 2, None]), TensorShape(None).
Parameters
-
object
other - Another `TensorShape`.
Returns
-
object
- A `TensorShape` which is the most specific compatible shape of `self` and `other`.
object num_elements_dyn()
Returns the total number of elements, or none for incomplete shapes.
TensorShape with_rank(int rank)
Returns a shape based on `self` with the given rank. This method promotes a completely unknown shape to one with a
known rank.
Parameters
-
int
rank - An integer.
Returns
-
TensorShape
- A shape that is at least as specific as `self` with the given rank.
TensorShape with_rank(IGraphNodeBase rank)
Returns a shape based on `self` with the given rank. This method promotes a completely unknown shape to one with a
known rank.
Parameters
-
IGraphNodeBase
rank - An integer.
Returns
-
TensorShape
- A shape that is at least as specific as `self` with the given rank.
TensorShape with_rank_at_least(int rank)
Returns a shape based on `self` with at least the given rank.
Parameters
-
int
rank - An integer.
Returns
-
TensorShape
- A shape that is at least as specific as `self` with at least the given rank.
object with_rank_at_least_dyn(object rank)
Returns a shape based on `self` with at least the given rank.
Parameters
-
object
rank - An integer.
Returns
-
object
- A shape that is at least as specific as `self` with at least the given rank.
TensorShape with_rank_at_most(int rank)
Returns a shape based on `self` with at most the given rank.
Parameters
-
int
rank - An integer.
Returns
-
TensorShape
- A shape that is at least as specific as `self` with at most the given rank.
object with_rank_at_most_dyn(object rank)
Returns a shape based on `self` with at most the given rank.
Parameters
-
object
rank - An integer.
Returns
-
object
- A shape that is at least as specific as `self` with at most the given rank.
object with_rank_dyn(object rank)
Returns a shape based on `self` with the given rank. This method promotes a completely unknown shape to one with a
known rank.
Parameters
-
object
rank - An integer.
Returns
-
object
- A shape that is at least as specific as `self` with the given rank.
Public static methods
TensorShape Get(Array array)
Public properties
IList<Dimension> dims get;
Returns a list of Dimensions, or None if the shape is unspecified.
object dims_dyn get;
Returns a list of Dimensions, or None if the shape is unspecified.
object Item get;
Nullable<int> ndims get;
Deprecated accessor for `rank`.
object ndims_dyn get;
Deprecated accessor for `rank`.
object PythonObject get;
Nullable<int> rank get;
Returns the rank of this shape, or None if it is unspecified.
object rank_dyn get;
Returns the rank of this shape, or None if it is unspecified.