tf.TensorShape

View source on GitHub

Represents the shape of a Tensor.

tf.TensorShape(
    dims
)

A TensorShape represents a possibly-partial shape specification for a Tensor. It may be one of the following:

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 for details of shape functions and how to register them. Alternatively, the shape may be set explicitly using tf.Tensor.set_shape.

Args:

Attributes:

Raises:

Methods

__add__

View source

__add__(
    other
)

__bool__

View source

__bool__()

Returns True if this shape contains non-zero information.

__concat__

View source

__concat__(
    other
)

__eq__

View source

__eq__(
    other
)

Returns True if self is equivalent to other.

__getitem__

View source

__getitem__(
    key
)

Returns the value of a dimension or a shape, depending on the key.

Args:

Returns:

An integer if key is an integer, or a TensorShape if key is a slice.

Raises:

__iter__

View source

__iter__()

Returns self.dims if the rank is known, otherwise raises ValueError.

__len__

View source

__len__()

Returns the rank of this shape, or raises ValueError if unspecified.

__ne__

View source

__ne__(
    other
)

Returns True if self is known to be different from other.

__nonzero__

View source

__nonzero__()

Returns True if this shape contains non-zero information.

__radd__

View source

__radd__(
    other
)

as_list

View source

as_list()

Returns a list of integers or None for each dimension.

Returns:

A list of integers or None for each dimension.

Raises:

as_proto

View source

as_proto()

Returns this shape as a TensorShapeProto.

assert_has_rank

View source

assert_has_rank(
    rank
)

Raises an exception if self is not compatible with the given rank.

Args:

Raises:

assert_is_compatible_with

View source

assert_is_compatible_with(
    other
)

Raises exception if self and other do not represent the same shape.

This method can be used to assert that there exists a shape that both self and other represent.

Args:

Raises:

assert_is_fully_defined

View source

assert_is_fully_defined()

Raises an exception if self is not fully defined in every dimension.

Raises:

assert_same_rank

View source

assert_same_rank(
    other
)

Raises an exception if self and other do not have compatible ranks.

Args:

Raises:

concatenate

View source

concatenate(
    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.

Args:

Returns:

A TensorShape whose dimensions are the concatenation of the dimensions in self and other.

is_compatible_with

View source

is_compatible_with(
    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:

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]).

Args:

Returns:

True iff self is compatible with other.

is_fully_defined

View source

is_fully_defined()

Returns True iff self is fully defined in every dimension.

merge_with

View source

merge_with(
    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().

Args:

Returns:

A TensorShape containing the combined information of self and other.

Raises:

most_specific_compatible_shape

View source

most_specific_compatible_shape(
    other
)

Returns the most specific TensorShape compatible with self and other.

Args:

Returns:

A TensorShape which is the most specific compatible shape of self and other.

num_elements

View source

num_elements()

Returns the total number of elements, or none for incomplete shapes.

with_rank

View source

with_rank(
    rank
)

Returns a shape based on self with the given rank.

This method promotes a completely unknown shape to one with a known rank.

Args:

Returns:

A shape that is at least as specific as self with the given rank.

Raises:

with_rank_at_least

View source

with_rank_at_least(
    rank
)

Returns a shape based on self with at least the given rank.

Args:

Returns:

A shape that is at least as specific as self with at least the given rank.

Raises:

with_rank_at_most

View source

with_rank_at_most(
    rank
)

Returns a shape based on self with at most the given rank.

Args:

Returns:

A shape that is at least as specific as self with at most the given rank.

Raises: