Skip to content
Related Articles

Related Articles

Improve Article

Tensorflow.js tf.initializers.zeros() Function

  • Last Updated : 25 Jul, 2021
Geek Week

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

The tf.initializers.zeros() function is an initializer that is used to produce tensors that are initialized to zero.

Syntax:

tf.initializers.zeros()

Parameters: This method does not accept any parameter.

Return Value: It returns zeros.



Example 1:

Javascript




// Importing the tensorflow.Js library
import * as tf from "@tensorflow/tfjs"
  
// Calling tf.initializers.zeros() function
const initializer = tf.initializers.zeros();
  
// Printing output
console.log(JSON.stringify(+initializer));

Output:

null

Example 2:

Javascript




// Importing the tensorflow.Js library
import * as tf from "@tensorflow/tfjs"
  
// Calling tf.initializers.zeros() function
const initializer = tf.initializers.zeros();
  
// Defining shape and dtype w.r.t initializer
const x = initializer.shape = [ [1, 2], [3, 5]];
const y = initializer.dtype = 'int32';
  
// Printing output
console.log(initializer);
console.log(JSON.stringify(+initializer));

Output:

{
  "shape": [
    [
      1,
      2
    ],
    [
      3,
      5
    ]
  ],
  "dtype": "int32"
}
null

Reference: https://js.tensorflow.org/api/latest/#initializers.zeros

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!

My Personal Notes arrow_drop_up
Recommended Articles
Page :