# tf.data.experimental.cardinality

<br />

|---|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png) TensorFlow 2 version](https://www.tensorflow.org/api_docs/python/tf/data/experimental/cardinality) | [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/data/experimental/ops/cardinality.py#L32-L51) |

Returns the cardinality of `dataset`, if known.

#### View aliases


**Compat aliases for migration**

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

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

<br />

    tf.data.experimental.cardinality(
        dataset
    )

The operation returns the cardinality of `dataset`. The operation may return
[`tf.data.experimental.INFINITE_CARDINALITY`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/data/experimental#INFINITE_CARDINALITY) if `dataset` contains an infinite
number of elements or [`tf.data.experimental.UNKNOWN_CARDINALITY`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/data/experimental#UNKNOWN_CARDINALITY) if the
analysis fails to determine the number of elements in `dataset` (e.g. when the
dataset source is a file).

<br />

<br />

<br />

| ## Args ||
|---|---|
| `dataset` | A [`tf.data.Dataset`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/data/Dataset) for which to determine cardinality. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A scalar [`tf.int64`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf#int64) `Tensor` representing the cardinality of `dataset`. If the cardinality is infinite or unknown, the operation returns the named constant `INFINITE_CARDINALITY` and `UNKNOWN_CARDINALITY` respectively. ||

<br />