Tensorflow.js tf.all() Function
Last Updated :
11 Jan, 2022
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
import * as tf from "@tensorflow/tfjs"
const gfg = tf.tensor1d([1, 2, 3], 'bool' );
gfg.all().print();
|
Output:
Tensor
true
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs"
const x = tf.tensor2d([1, 1, 0, 0], [4, 1], 'bool' );
const axis = 1;
x.all(axis).print();
|
Output:
Tensor
[true, true, false, false]
Reference: https://js.tensorflow.org/api/latest/#all
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...