Wednesday, July 3, 2024
HomeLanguagesJavascriptTensorflow.js tf.print() Function

Tensorflow.js tf.print() Function

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.

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Calisto Chipfumbu
Calisto Chipfumbuhttp://cchipfumbu@gmail.com
I have 5 years' worth of experience in the IT industry, primarily focused on Linux and Database administration. In those years, apart from learning significant technical knowledge, I also became comfortable working in a professional team and adapting to my environment, as I switched through 3 roles in that time.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments