Model data flow
Represent inputs, intermediate values, and outputs in TensorFlow computations.
TensorFlow · Class
tf.Tensor is TensorFlow’s immutable, multidimensional array type. Its elements share one dtype, and the tensor carries a shape for use in eager or graph-based computation.
A tf.Tensor is TensorFlow's immutable, typed multidimensional data object. It carries a shape and element type, and operations can run immediately in eager execution or as part of a graph for later evaluation.
class tf.Tensorimport tensorflow as tf
c = tf.constant([[1.0, 2.0], [3.0, 4.0]])
d = tf.constant([[1.0, 1.0], [0.0, 1.0]])
e = tf.matmul(c, d)
print(e)Creates two rank-2 tensors and multiplies them with a TensorFlow operation.
Represent inputs, intermediate values, and outputs in TensorFlow computations.
Store typed multidimensional values for arithmetic and linear algebra operations.
Build deferred computations that can be evaluated later.
A tf.Tensor is a multidimensional array whose elements share one known data type. It also has a shape, and it is the primary object passed between TensorFlow operations.
Follow-up: How does execution differ between modes? In eager execution operations run immediately; in graph execution TensorFlow builds a computation graph for later evaluation.
TensorFlow supports eager and graph execution. Eager execution is the default, while graph execution constructs operations for later evaluation.
Follow-up: Why might graph execution be useful? A graph separates construction from evaluation, allowing the computation to be represented and run later.
Regular tensors are immutable, so an operation returns a tensor rather than changing an existing tensor's contents. Use tf.Variable for mutable state such as model weights.
Follow-up: What property must tensor elements share? All elements must have one common known data type, such as float32, int32, or string.
tf.constanttf.Variabletf.matmultf.convert_to_tensor