Open In App

Tensorflow.js tf.any() Function

Last Updated : 21 May, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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:

  • x: the tensors to input.
  • Axis: The dimension(s) to reduce.
  • keepDims: If true, retains reduced elements with size 1.

Return Value: It returns tf.Tensor

Example 1:

Javascript




// 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:

Javascript




// 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


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads