Friday, January 10, 2025
Google search engine
HomeLanguagesJavascriptTensorflow.js tf.step() Function

Tensorflow.js tf.step() 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.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]
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments