# tf.compat.v1.Dimension

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/tensor_shape.py#L185-L722) |

Represents the value of one dimension in a TensorShape.

    tf.compat.v1.Dimension(
        value
    )

<br />

## Migrate to TF2

<br />

> [!CAUTION]
> **Caution:** This API was designed for TensorFlow v1. Continue reading for details on how to migrate from this API to a native TensorFlow v2 equivalent. See the [TensorFlow v1 to TensorFlow v2 migration guide](https://www.tensorflow.org/guide/migrate) for instructions on how to migrate the rest of your code.

In TF2, members of a `TensorShape` object are integers. The `Dimension` class
is not part of TF2's data model.

Please refer to the [TensorShape section of the migration guide](https://www.tensorflow.org/guide/migrate/index#tensorshape) on common code
patterns adapting Dimension objects to a TF2 syntax.

<br />

<br />

## Description

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `value` | The value of this dimension, or None if it is unknown. |

<br />

## Methods

### `assert_is_compatible_with`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/tensor_shape.py#L289-L301)

    assert_is_compatible_with(
        other
    )

Raises an exception if `other` is not compatible with this Dimension.

<br />

<br />

<br />

| Args ||
|---|---|
| `other` | Another Dimension. |

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `ValueError` | If `self` and `other` are not compatible (see is_compatible_with). |

<br />

### `is_compatible_with`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/tensor_shape.py#L273-L287)

    is_compatible_with(
        other
    )

Returns true if `other` is compatible with this Dimension.

Two known Dimensions are compatible if they have the same value.
An unknown Dimension is compatible with all other Dimensions.

<br />

<br />

<br />

| Args ||
|---|---|
| `other` | Another Dimension. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| True if this Dimension and `other` are compatible. ||

<br />

### `merge_with`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/tensor_shape.py#L303-L338)

    merge_with(
        other
    )

Returns a Dimension that combines the information in `self` and `other`.

Dimensions are combined as follows:

    tf.compat.v1.Dimension(n)   .merge_with(tf.compat.v1.Dimension(n))     ==
    tf.compat.v1.Dimension(n)
    tf.compat.v1.Dimension(n)   .merge_with(tf.compat.v1.Dimension(None))  ==
    tf.compat.v1.Dimension(n)
    tf.compat.v1.Dimension(None).merge_with(tf.compat.v1.Dimension(n))     ==
    tf.compat.v1.Dimension(n)
    # equivalent to tf.compat.v1.Dimension(None)
    tf.compat.v1.Dimension(None).merge_with(tf.compat.v1.Dimension(None))

    # raises ValueError for n != m
    tf.compat.v1.Dimension(n)   .merge_with(tf.compat.v1.Dimension(m))

<br />

<br />

<br />

| Args ||
|---|---|
| `other` | Another Dimension. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A Dimension containing the combined information of `self` and `other`. ||

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `ValueError` | If `self` and `other` are not compatible (see is_compatible_with). |

<br />

### `__add__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/tensor_shape.py#L340-L369)

    __add__(
        other
    )

Returns the sum of `self` and `other`.

Dimensions are summed as follows:

    tf.compat.v1.Dimension(m)    + tf.compat.v1.Dimension(n)     ==
    tf.compat.v1.Dimension(m + n)
    tf.compat.v1.Dimension(m)    + tf.compat.v1.Dimension(None)  # equiv. to
    tf.compat.v1.Dimension(None)
    tf.compat.v1.Dimension(None) + tf.compat.v1.Dimension(n)     # equiv. to
    tf.compat.v1.Dimension(None)
    tf.compat.v1.Dimension(None) + tf.compat.v1.Dimension(None)  # equiv. to
    tf.compat.v1.Dimension(None)

<br />

<br />

<br />

| Args ||
|---|---|
| `other` | Another Dimension, or a value accepted by `as_dimension`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A Dimension whose value is the sum of `self` and `other`. ||

<br />

### `__bool__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/tensor_shape.py#L251-L253)

    __bool__()

Equivalent to `bool(self.value)`.

### `__div__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/tensor_shape.py#L517-L531)

    __div__(
        other
    )

> [!WARNING]
> **Deprecated:** Use `__floordiv__` via `x // y` instead.

This function exists only for backwards compatibility purposes; new code
should use `__floordiv__` via the syntax `x // y`. Using `x // y`
communicates clearly that the result rounds down, and is forward compatible
to Python 3.

<br />

<br />

<br />

| Args ||
|---|---|
| `other` | Another `Dimension`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A `Dimension` whose value is the integer quotient of `self` and `other`. ||

<br />

### `__eq__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/tensor_shape.py#L231-L239)

    __eq__(
        other
    )

Returns true if `other` has the same known value as this Dimension.

### `__floordiv__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/tensor_shape.py#L471-L500)

    __floordiv__(
        other
    )

Returns the quotient of `self` and `other` rounded down.

Dimensions are divided as follows:

    tf.compat.v1.Dimension(m)    // tf.compat.v1.Dimension(n)     ==
    tf.compat.v1.Dimension(m // n)
    tf.compat.v1.Dimension(m)    // tf.compat.v1.Dimension(None)  # equiv. to
    tf.compat.v1.Dimension(None)
    tf.compat.v1.Dimension(None) // tf.compat.v1.Dimension(n)     # equiv. to
    tf.compat.v1.Dimension(None)
    tf.compat.v1.Dimension(None) // tf.compat.v1.Dimension(None)  # equiv. to
    tf.compat.v1.Dimension(None)

<br />

<br />

<br />

| Args ||
|---|---|
| `other` | Another Dimension, or a value accepted by `as_dimension`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A `Dimension` whose value is the integer quotient of `self` and `other`. ||

<br />

### `__ge__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/tensor_shape.py#L696-L719)

    __ge__(
        other
    )

Returns True if `self` is known to be greater than or equal to `other`.

Dimensions are compared as follows:

    (tf.compat.v1.Dimension(m)    >= tf.compat.v1.Dimension(n))    == (m >= n)
    (tf.compat.v1.Dimension(m)    >= tf.compat.v1.Dimension(None)) == None
    (tf.compat.v1.Dimension(None) >= tf.compat.v1.Dimension(n))    == None
    (tf.compat.v1.Dimension(None) >= tf.compat.v1.Dimension(None)) == None

<br />

<br />

<br />

| Args ||
|---|---|
| `other` | Another Dimension. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| The value of `self.value >= other.value` if both are known, otherwise None. ||

<br />

### `__gt__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/tensor_shape.py#L671-L694)

    __gt__(
        other
    )

Returns True if `self` is known to be greater than `other`.

Dimensions are compared as follows:

    (tf.compat.v1.Dimension(m)    > tf.compat.v1.Dimension(n))    == (m > n)
    (tf.compat.v1.Dimension(m)    > tf.compat.v1.Dimension(None)) == None
    (tf.compat.v1.Dimension(None) > tf.compat.v1.Dimension(n))    == None
    (tf.compat.v1.Dimension(None) > tf.compat.v1.Dimension(None)) == None

<br />

<br />

<br />

| Args ||
|---|---|
| `other` | Another Dimension. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| The value of `self.value > other.value` if both are known, otherwise None. ||

<br />

### `__le__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/tensor_shape.py#L646-L669)

    __le__(
        other
    )

Returns True if `self` is known to be less than or equal to `other`.

Dimensions are compared as follows:

    (tf.compat.v1.Dimension(m)    <= tf.compat.v1.Dimension(n))    == (m <= n)
    (tf.compat.v1.Dimension(m)    <= tf.compat.v1.Dimension(None)) == None
    (tf.compat.v1.Dimension(None) <= tf.compat.v1.Dimension(n))    == None
    (tf.compat.v1.Dimension(None) <= tf.compat.v1.Dimension(None)) == None

<br />

<br />

<br />

| Args ||
|---|---|
| `other` | Another Dimension. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| The value of `self.value <= other.value` if both are known, otherwise None. ||

<br />

### `__lt__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/tensor_shape.py#L621-L644)

    __lt__(
        other
    )

Returns True if `self` is known to be less than `other`.

Dimensions are compared as follows:

    (tf.compat.v1.Dimension(m)    < tf.compat.v1.Dimension(n))    == (m < n)
    (tf.compat.v1.Dimension(m)    < tf.compat.v1.Dimension(None)) == None
    (tf.compat.v1.Dimension(None) < tf.compat.v1.Dimension(n))    == None
    (tf.compat.v1.Dimension(None) < tf.compat.v1.Dimension(None)) == None

<br />

<br />

<br />

| Args ||
|---|---|
| `other` | Another Dimension. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| The value of `self.value < other.value` if both are known, otherwise None. ||

<br />

### `__mod__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/tensor_shape.py#L581-L607)

    __mod__(
        other
    )

Returns `self` modulo `other`.

Dimension modulo are computed as follows:

    tf.compat.v1.Dimension(m)    % tf.compat.v1.Dimension(n)     ==
    tf.compat.v1.Dimension(m % n)
    tf.compat.v1.Dimension(m)    % tf.compat.v1.Dimension(None)  # equiv. to
    tf.compat.v1.Dimension(None)
    tf.compat.v1.Dimension(None) % tf.compat.v1.Dimension(n)     # equiv. to
    tf.compat.v1.Dimension(None)
    tf.compat.v1.Dimension(None) % tf.compat.v1.Dimension(None)  # equiv. to
    tf.compat.v1.Dimension(None)

<br />

<br />

<br />

| Args ||
|---|---|
| `other` | Another Dimension, or a value accepted by `as_dimension`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A Dimension whose value is `self` modulo `other`. ||

<br />

### `__mul__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/tensor_shape.py#L428-L458)

    __mul__(
        other
    )

Returns the product of `self` and `other`.

Dimensions are summed as follows:

    tf.compat.v1.Dimension(m)    * tf.compat.v1.Dimension(n)     ==
    tf.compat.v1.Dimension(m * n)
    tf.compat.v1.Dimension(m)    * tf.compat.v1.Dimension(None)  # equiv. to
    tf.compat.v1.Dimension(None)
    tf.compat.v1.Dimension(None) * tf.compat.v1.Dimension(n)     # equiv. to
    tf.compat.v1.Dimension(None)
    tf.compat.v1.Dimension(None) * tf.compat.v1.Dimension(None)  # equiv. to
    tf.compat.v1.Dimension(None)

<br />

<br />

<br />

| Args ||
|---|---|
| `other` | Another Dimension, or a value accepted by `as_dimension`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A Dimension whose value is the product of `self` and `other`. ||

<br />

### `__ne__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/tensor_shape.py#L241-L249)

    __ne__(
        other
    )

Returns true if `other` has a different known value from `self`.

### `__radd__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/tensor_shape.py#L371-L380)

    __radd__(
        other
    )

Returns the sum of `other` and `self`.

<br />

<br />

<br />

| Args ||
|---|---|
| `other` | Another Dimension, or a value accepted by `as_dimension`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A Dimension whose value is the sum of `self` and `other`. ||

<br />

### `__rdiv__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/tensor_shape.py#L533-L547)

    __rdiv__(
        other
    )

Use `__floordiv__` via `x // y` instead.

This function exists only to have a better error message. Instead of:
`TypeError: unsupported operand type(s) for /: 'int' and 'Dimension'`,
this function will explicitly call for usage of `//` instead.

<br />

<br />

<br />

| Args ||
|---|---|
| `other` | Another `Dimension`. |

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| TypeError. ||

<br />

### `__rfloordiv__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/tensor_shape.py#L502-L515)

    __rfloordiv__(
        other
    )

Returns the quotient of `other` and `self` rounded down.

<br />

<br />

<br />

| Args ||
|---|---|
| `other` | Another Dimension, or a value accepted by `as_dimension`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A `Dimension` whose value is the integer quotient of `self` and `other`. ||

<br />

### `__rmod__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/tensor_shape.py#L609-L619)

    __rmod__(
        other
    )

Returns `other` modulo `self`.

<br />

<br />

<br />

| Args ||
|---|---|
| `other` | Another Dimension, or a value accepted by `as_dimension`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A Dimension whose value is `other` modulo `self`. ||

<br />

### `__rmul__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/tensor_shape.py#L460-L469)

    __rmul__(
        other
    )

Returns the product of `self` and `other`.

<br />

<br />

<br />

| Args ||
|---|---|
| `other` | Another Dimension, or a value accepted by `as_dimension`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A Dimension whose value is the product of `self` and `other`. ||

<br />

### `__rsub__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/tensor_shape.py#L413-L426)

    __rsub__(
        other
    )

Returns the subtraction of `self` from `other`.

<br />

<br />

<br />

| Args ||
|---|---|
| `other` | Another Dimension, or a value accepted by `as_dimension`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A Dimension whose value is the subtraction of `self` from `other`. ||

<br />

### `__rtruediv__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/tensor_shape.py#L565-L579)

    __rtruediv__(
        other
    )

Use `__floordiv__` via `x // y` instead.

This function exists only to have a better error message. Instead of:
`TypeError: unsupported operand type(s) for /: 'int' and 'Dimension'`,
this function will explicitly call for usage of `//` instead.

<br />

<br />

<br />

| Args ||
|---|---|
| `other` | Another `Dimension`. |

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| TypeError. ||

<br />

### `__sub__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/tensor_shape.py#L382-L411)

    __sub__(
        other
    )

Returns the subtraction of `other` from `self`.

Dimensions are subtracted as follows:

    tf.compat.v1.Dimension(m)    - tf.compat.v1.Dimension(n)     ==
    tf.compat.v1.Dimension(m - n)
    tf.compat.v1.Dimension(m)    - tf.compat.v1.Dimension(None)  # equiv. to
    tf.compat.v1.Dimension(None)
    tf.compat.v1.Dimension(None) - tf.compat.v1.Dimension(n)     # equiv. to
    tf.compat.v1.Dimension(None)
    tf.compat.v1.Dimension(None) - tf.compat.v1.Dimension(None)  # equiv. to
    tf.compat.v1.Dimension(None)

<br />

<br />

<br />

| Args ||
|---|---|
| `other` | Another Dimension, or a value accepted by `as_dimension`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A Dimension whose value is the subtraction of `other` from `self`. ||

<br />

### `__truediv__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/framework/tensor_shape.py#L549-L563)

    __truediv__(
        other
    )

Use `__floordiv__` via `x // y` instead.

This function exists only to have a better error message. Instead of:
`TypeError: unsupported operand type(s) for /: 'Dimension' and 'int'`,
this function will explicitly call for usage of `//` instead.

<br />

<br />

<br />

| Args ||
|---|---|
| `other` | Another `Dimension`. |

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| TypeError. ||

<br />