Skip to content
Related Articles
Open in App
Not now

Related Articles

Tensorflow.js tf.all() Function

Improve Article
Save Article
  • Last Updated : 11 Jan, 2022
Improve Article
Save 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. 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

 

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!