Open In App

Tensorflow.js tf.step() Function

Improve
Improve
Like Article
Like
Save
Share
Report

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.step() function is used to return the step of the input tensor’s elements i.e. it returns 1 if the element is greater than 0 else return alpha, where alpha is the parameter of the function step().

Syntax:

tf.step (x, alpha)

Parameters: This function accepts two parameters which are illustrated below:

  • x: The specified input tensor.
  • alpha: The gradient for the negative input value.

Return Value: It returns the step of the input tensor’s elements.

Example 1:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Initializing a tensor of some elements
const x = tf.tensor1d([2, 0, -2, -5]);
  
// Calling the .step() function over
// the above tensor as its parameter and
// for the alpha value .2
x.step(.2).print();


Output:

Tensor
   [1, 0.2, 0.2, 0.2]

Example 2:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Using a tensor of some elements as 
// the parameter for the .step() function with
// alpha value of 6
tf.tensor1d([0, .8, -1, -5.4]).step(6).print();


Output:

Tensor
   [6, 1, 6, 6]

Last Updated : 10 May, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads