/  Deep Learning Interview questions and answers   /  What do you mean by Tensor and Explain about Tensor Datatype and Ranks? ## What do you mean by Tensor and Explain about Tensor Datatype and Ranks?

A tensor is often thought of as a generalized matrix. That is, it could be a 1-D matrix (a vector is actually such a tensor), a 3-D matrix (something like a cube of numbers), even a 0-D matrix (a single number), or a higher dimensional structure that is harder to visualize. The dimension of the tensor is called its rank.

A tensor is a mathematical entity that lives in a structure and interacts with other mathematical entities. If one transforms the other entities in the structure in a regular way, then the tensor must obey a related transformation rule. ### Tensor Data Type

Tensors have a data type. Refer to the tf.DType page for a complete list of the data types.

It is not possible to have a tf.Tensor with more than one data type. It is possible, however, to serialize arbitrary data structures as strings and store those in tf.Tensors.

It is possible to cast tf.Tensors from one datatype to another using tf.cast:

# Cast a constant integer tensor into floating point.
float_tensor = tf.cast(tf.constant([1, 2, 3]), dtype=tf.float32)
To inspect a tf.Tensor‘s data type use the Tensor.dtype property.

When creating a tf.Tensor from a python object you may optionally specify the datatype. If you don’t, TensorFlow chooses a datatype that can represent your data. TensorFlow converts Python integers to tf.int32 and python floating point numbers to tf.float32. Otherwise TensorFlow uses the same rules numpy uses when converting to arrays.

### Tensor Rank

The rank of a tf.Tensor object is its number of dimensions. Synonyms for rank include order or degree or n-dimension. Note that rank in TensorFlow is not the same as matrix rank in mathematics. As the following table shows, each rank in TensorFlow corresponds to a different mathematical entity:

 Rank Math entity 0 Scalar (magnitude only) 1 Vector (magnitude and direction) 2 Matrix (table of numbers) 3 3-Tensor (cube of numbers) n n-Tensor (you get the idea) 