TensorFlow

API

 tf / is_tensor


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

Use is_tensor to differentiate types that can ingested by TensorFlow ops without any conversion (e.g., tf.Tensor, tf.SparseTensor, and 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.dtype

we check to make sure that t is a tensor (and convert it if not) before accessing its shape and dtype.

x A python object to check.

True if x is a tensor or "tensor-like", False if not.

此页内容是否对您有帮助