nerdexam
Huawei

H13-311_V3.5 · Question #241

TensorF1ow2.0 Can be used to check if it is tensor The methods are?

The correct answer is B. isinstance C. is_tensor. In TensorFlow 2.0, both isinstance(x, tf.Tensor) and tf.is_tensor(x) are valid ways to check whether an object is a tensor - isinstance is the standard Python introspection approach, while tf.is_tensor() is TensorFlow's built-in utility that also returns True for tf.Variable…

Deep Learning Basics

Question

TensorF1ow2.0 Can be used to check if it is tensor The methods are?

Options

  • Adtype
  • Bisinstance
  • Cis_tensor
  • Ddevice

How the community answered

(50 responses)
  • A
    18% (9)
  • B
    74% (37)
  • D
    8% (4)

Explanation

In TensorFlow 2.0, both isinstance(x, tf.Tensor) and tf.is_tensor(x) are valid ways to check whether an object is a tensor - isinstance is the standard Python introspection approach, while tf.is_tensor() is TensorFlow's built-in utility that also returns True for tf.Variable objects, making it the more TensorFlow-idiomatic choice.

A (dtype) is wrong because dtype is an attribute of a tensor (e.g., tensor.dtype returns tf.float32), not a method for checking if something is a tensor - calling it on a non-tensor will raise an AttributeError.

D (device) is wrong for the same reason - it's an attribute that tells you where a tensor lives (CPU/GPU), not a predicate that tells you what it is.

Memory tip: Both correct answers contain the word "is" in spirit - isinstance asks "is it an instance of?" and is_tensor asks "is it a tensor?" - if your method is phrasing a yes/no existence question, it's probably a checker.

Topics

#TensorFlow 2.0#Type Checking#Tensor API#Data Types

Community Discussion

No community discussion yet for this question.

Full H13-311_V3.5 Practice