Saturday, November 16, 2024
Google search engine
HomeLanguagesJavascriptTensorflow.js tf.all() Function

Tensorflow.js tf.all() 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. It also helps the developers to develop ML models in JavaScript language and can use ML directly in the browser or Node.js.

The tf. all() function is used to compute the logical and of elements across dimensions of a tf.Tensor.

Syntax:

tf.all(x, axis?, keepDims?)

Parameters:

  • x: The input tensor.
  • axis: The dimension(s) to reduce.
  • keepDims: If true, retains reduced dimensions with size 1.

Return Value: It returns tf.Tensor

Example 1:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
const gfg = tf.tensor1d([1, 2, 3], 'bool');
 
gfg.all().print();


 
 

Output:

 

Tensor
    true

 

Example 2:

 

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
const x = tf.tensor2d([1, 1, 0, 0], [4, 1], 'bool');
 
// Initialize the axis
const axis = 1;
x.all(axis).print();


 
 

Output:

 

Tensor
   [true, true, false, false]

 

Reference: https://js.tensorflow.org/api/latest/#all

 

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