Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Tensorflow.js tf.step() Function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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]
My Personal Notes arrow_drop_up
Last Updated : 10 May, 2021
Like Article
Save Article
Similar Reads
Related Tutorials