Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Tensorflow.js tf.print() Function

  • Last Updated : 10 May, 2021

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. It helps developers to develop ML models in JavaScript, and use ML directly in the browser or in Node.js.

The tf.print() function is used to print information about the tf.tensor along with its data.

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

Syntax:

tf.print (x, verbose)

Parameter:



  • x: The tensor which is to be printed
  • verbose: It is an optional argument. These are the boolean parameter which decides whether to print the verbose information about the Tensor, including dtype and size.

Return: It returns nothing i.e, void.

Example 1:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Setting the value of verbose
const verbose = true;
  
// Creating the tensor
var val = tf.tensor2d([8, 2, 5, 6], [2, 2]);
  
// Printing the tensor
val.print(verbose)

Output:

Tensor
   dtype: float32
   rank: 2
   shape: [2,2]
   values:
      [[8, 2],
       [5, 6]]

Example 2:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Setting the value of verbose
const verbose = false;
  
// Creating the tensor
var val = tf.tensor2d([8, 2, 5, 6], [2, 2]);
  
// Printing the tensor
val.print(verbose)

Output:

Tensor
   [[8, 2],
    [5, 6]]

Reference: https://js.tensorflow.org/api/3.4.0/#print

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!