Open In App

Tensorflow.js tf.initializers.zeros() Function

Last Updated : 25 Jul, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads