Open In App

Tensorflow.js tf.Tensor class .print() Method

Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment.

The tf.print() function is used to Prints information about the tf.Tensor including its data.



Syntax:

tf.print(value, verbose)

Parameters:



The below examples demonstrate the tf.print() function:

Example 1: In this example, we use the ts.tensor2d to create a tensor, and we are printing using tf.print function using the verbose value as true.




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Creating the tensor
const verbose = true;
var val = tf.tensor2d(["geeks","for","geeks","website"], [2, 2]);
  
// Printing the tensor
val.print(verbose);

Output:

Tensor
  dtype: string
  rank: 2
  shape: [2,2]
  values:
    [['geeks', 'for'    ],
     ['geeks', 'website']]

Example 2: In this example, we use the ts.tensor2d to create a tensor, and we are printing using tf.print function using the verbose value as false.




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Creating the tensor
const verbose = false;
var val = tf.tensor(["geeks","for","geeks"]);
  
// Printing the tensor
val.print(verbose);

Output:

Tensor
    ['geeks', 'for', 'geeks']

Reference:https://js.tensorflow.org/api/latest/#tf.Tensor.print

Article Tags :