Tensorflow – is_tensor() method
TensorFlow is an open-source Python library designed by Google to develop Machine Learning models and deep learning neural networks.
Tensors are used by many Tensorflow operations. Sometimes it is important to check whether given variable is a tensor or not before using it. is_tensor() method can be used to check this.
- is_tensor: This method takes a variable as input and returns True if variable is a Tensor or Tensor-like object otherwise it will return false.
Example 1: This example will print True if give variable is a Tensor otherwise it will print False.
Result: False Result: True
Example 2: This example checks if a variable is tensor or not, if not it will convert the variable into tensor.
Dtype: <dtype: 'int64'> tensor: tf.Tensor([1 2 3], shape=(3,), dtype=int64)