Open In App

Tensorflow.js tf.any() 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 the JavaScript language so that ML directly can be used in the browser or in Node.js.

The tf.any() function is mainly used to calculate the logical OR of elements across given dimensions for tf.Tensor.



Syntax:

tf.all(x, axis, keepDims)

Parameters:



Return Value: It returns tf.Tensor

Example 1:




// Importing @tensorflow/tfslibrary
const tf = require("@tensorflow/tfjs")
  
// Initialization of tensor1d
const gfg=tf.tensor1d([-1, -2, -3, -4], 'bool')
  
// Printing the boolean value
gfg.any().print();

Output:

Tensor
    true

Example 2:




// Importing @tensorflow/tfslibrary
const tf = require("@tensorflow/tfjs")
  
// Initialization of the axis
const axis = 1;
  
// Initialization 2d tensor of shape [2,2]
const gfg=tf.tensor2d([1, 1, 0, 0], [2, 2], 'bool')
  
gfg.any(axis).print()

Output:

Tensor
    [True, False]

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

Article Tags :