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
import * as tf from "@tensorflow/tfjs"
const x = tf.tensor1d([2, 0, -2, -5]);
x.step(.2).print();
|
Output:
Tensor
[1, 0.2, 0.2, 0.2]
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs"
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
Share your thoughts in the comments
Please Login to comment...