Tensorflow.js tf.lessEqual() 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.lessEqual() function is used to return the tensor of Boolean values for the two specified tensor values i.e. it returns true if the value of the first tensor is less than or equal to the second tensor value else returns false. It supports broadcasting.
Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!
Syntax:
tf.lessEqual(a, b)
Parameters: This function accepts two parameters which are illustrated below:
- a: The first input tensor.
- b: The second input tensor. It should have values of the same data type as tensor “a”.
Return Value: It returns the tensor of Boolean values i.e. true if the value of the first tensor is less than or equal to the second tensor value else returns false.
Example 1:
Javascript
// Importing the tensorflow.js libraryimport * as tf from "@tensorflow/tfjs" // Initializing two different tensorsconst a = tf.tensor1d([1, 3, 6, 7]);const b = tf.tensor1d([1, 4, 5, 9]); // Calling the .lessEqual() functiona.lessEqual(b).print(); |
Output:
Tensor [true, true, false, true]
Example 2:
Javascript
// Importing the tensorflow libraryimport * as tf from "@tensorflow/tfjs" // Calling the .lessEqual() function with two// Different tensors as its parameterstf.tensor1d([1.5, 2.060, 2, 0.05, 4.5]).lessEqual(tf.tensor1d([1.25, 2.60, 2.0, .5, 4.05])).print(); |
Output:
Tensor [false, true, true, true, false]


