Tensorflow.js tf.zeros() 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.
The tf.zeros() function is used to create a new tensor with all elements set to zero.
- shape: It takes the shape of the tensor we are going to generate.
- dataType: It is the type of tensor in the resulting element. It can be a ‘float32′, ‘int32′ or ‘bool’. It defaults to the “float32” value. It is an optional parameter.
Return Value: It returns the tensor of the given shape with all elements set to zero.
Example 1: In this example, we are creating a tensor of shape 1*1 using tf.zeros().
Example 2: In this example, we are creating a tensor of shape 2*2 using tf.zeros() and with dataType parameter.
Tensor [[false, false], [false, false]]
Example 3: In this example, we are creating a tensor of shape 1*1 using tf.zeros().
Tensor [[0, 0, 0], [0, 0, 0], [0, 0, 0]]