# tf.is_tensor

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.7.4/tensorflow/python/framework/tensor_util.py#L1034-L1064) |

Checks whether `x` is a TF-native type that can be passed to many TF ops.

#### View aliases


**Compat aliases for migration**

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

[`tf.compat.v1.is_tensor`](https://www.tensorflow.org/api_docs/python/tf/is_tensor)

<br />

    tf.is_tensor(
        x
    )

Use `is_tensor` to differentiate types that can ingested by TensorFlow ops
without any conversion (e.g., [`tf.Tensor`](https://www.tensorflow.org/versions/r2.7/api_docs/python/tf/Tensor), [`tf.SparseTensor`](https://www.tensorflow.org/versions/r2.7/api_docs/python/tf/sparse/SparseTensor), and
[`tf.RaggedTensor`](https://www.tensorflow.org/versions/r2.7/api_docs/python/tf/RaggedTensor)) from types that need to be converted into tensors before
they are ingested (e.g., numpy `ndarray` and Python scalars).

For example, in the following code block:

    if not tf.is_tensor(t):
      t = tf.convert_to_tensor(t)
    return t.shape, t.dtype

we check to make sure that `t` is a tensor (and convert it if not) before
accessing its `shape` and `dtype`. (But note that not all TensorFlow native
types have shapes or dtypes; [`tf.data.Dataset`](https://www.tensorflow.org/versions/r2.7/api_docs/python/tf/data/Dataset) is an example of a TensorFlow
native type that has neither shape nor dtype.)

<br />

<br />

<br />

| ## Args ||
|---|---|
| `x` | A python object to check. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| `True` if `x` is a TensorFlow-native type. ||

<br />