Tensorflow.js tf.squeeze() Function Last Updated : 31 May, 2021 Comments Improve Suggest changes Like Article Like Report Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .squeeze() function is used to discard the dimensions of length one out of the shape of a stated tf.Tensor. Syntax : tf.squeeze(x, axis?) Parameters: x: It is the stated tensor input which is to be squeezed, and it can be of type tf.Tensor, TypedArray, or Array.axis: It is an elective parameter that holds a list of numbers. It squeezes only the stated dimensions in case its specified. Moreover, the dimension index here begins with zero, and it's a flaw to compress a dimension whose length is not one. Return Value: It returns the tf.Tensor object. Example 1: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Defining tensor input elements const y = tf.tensor([11, 76, -4, 6], [2, 2, 1]); // Calling squeeze() method and // Printing output y.squeeze().print(); Output: Tensor [[11, 76], [-4, 6 ]] Example 2: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Calling squeeze() method with // all its parameter var res = tf.squeeze(tf.tensor( [2.1, 5.6, 8.6, 7.6], [4, 1]), [1] ); // Printing output res.print(); Output: Tensor [2.0999999, 5.5999999, 8.6000004, 7.5999999] Reference: https://js.tensorflow.org/api/latest/#squeeze Comment More infoAdvertise with us Next Article Tensorflow.js tf.squeeze() Function N nidhi1352singh Follow Improve Article Tags : JavaScript Web Technologies Tensorflow.js TensorFlow.js-Transformations Similar Reads Tensorflow.js tf.step() 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. The tf.step() function is used to return the step of the input tensor's elements i.e. it returns 1 if the element is greater than 0 el 1 min read Tensorflow.js tf.keep() Function Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .keep() function is used to hold a tensor input that is formed within a tf.tidy() method from being spontaneously d 1 min read Tensorflow.js tf.slice() 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 in Node.js. The tf. 1 min read Tensorflow.js tf.neg() Function Tensorflow.js is an open-source library which is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .neg() function is used to calculate -1 * x i.e. input tensor and is done element wise. Syntax: Â tf.neg(x) 1 min read Tensorflow.js tf.less() 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. The tf.less() function is used to return the tensor of Boolean values for the two specified tensor values i.e. it returns true if the 2 min read Like