# tf.compat.dimension_value

<br />

|---|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png) TensorFlow 2 version](https://www.tensorflow.org/api_docs/python/tf/compat/dimension_value) | [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/framework/tensor_shape.py#L98-L128) |

Compatibility utility required to allow for both V1 and V2 behavior in TF.

#### View aliases


**Main aliases**

\`tf.dimension_value\`
**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.compat.dimension_value`](https://www.tensorflow.org/api_docs/python/tf/compat/dimension_value), [`tf.compat.v1.dimension_value`](https://www.tensorflow.org/api_docs/python/tf/compat/dimension_value), \`tf.compat.v2.compat.dimension_value\`

<br />

    tf.compat.dimension_value(
        dimension
    )

Until the release of TF 2.0, we need the legacy behavior of `TensorShape` to
coexist with the new behavior. This utility is a bridge between the two.

When accessing the value of a TensorShape dimension,
use this utility, like this:

    # If you had this in your V1 code:
    value = tensor_shape[i].value

    # Use `dimension_value` as direct replacement compatible with both V1 & V2:
    value = dimension_value(tensor_shape[i])

    # This would be the V2 equivalent:
    value = tensor_shape[i]  # Warning: this will return the dim value in V2!

<br />

<br />

<br />

| ## Arguments ||
|---|---|
| `dimension` | Either a `Dimension` instance, an integer, or None. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A plain value, i.e. an integer or None. ||

<br />