tf.print

Print the specified inputs.

Used in the notebooks

Used in the guide Used in the tutorials

A TensorFlow operator that prints the specified inputs to a desired output stream or logging level. The inputs may be dense or sparse Tensors, primitive python objects, data structures that contain tensors, and printable Python objects. Printed tensors will recursively show the first and last elements of each dimension to summarize.

Example:

Single-input usage:

tensor = tf.range(10)
tf.print(tensor, output_stream=sys.stderr)

(This prints "[0 1 2 ... 7 8 9]" to sys.stderr)

Multi-input usage:

tensor = tf.range(10)
tf.print("tensors:", tensor, {2: tensor * 2}, output_stream=sys.stdout)

(This prints "tensors: [0 1 2 ... 7 8 9] {2: [0 2 4 ... 14 16 18]}" to sys.stdout)

Changing the input separator:

tensor_a = tf.range(2)
tensor_b = tensor_a * 2
tf.print(tensor_a, tensor_b, output_stream=sys.stderr, sep=',')

(This prints "[0 1],[0 2]" to sys.stderr)

Usage in a tf.function:

@tf.function
def f():
    tensor = tf.range(10)
    tf.print(tensor, output_stream=sys.stderr)
    return tensor

range_tensor = f()

(This prints "[0 1 2 ... 7 8 9]" to sys.stderr)

@compatibility(TF 1.x Graphs and Sessions) In graphs manually created outside of tf.function, this method returns the created TF operator that prints the data. To make sure the operator runs, users need to