Tensorflow.js tf.keep() Function Last Updated : 01 Jun, 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 .keep() function is used to hold a tensor input that is formed within a tf.tidy() method from being spontaneously discarded. Syntax: tf.keep(result) Parameters: result: It is the stated tensor input which is to be held from being discarded. Return Value: It returns tf.Tensor object. Example 1: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Declaring a variable let res1; // Calling tidy method const res2 = tf.tidy(() => { // Defining result parameter const result = tf.scalar(121); // Calling tf.keep() method res1 = tf.keep(result.sqrt()); }); // Printing output res1.print(); Output: Tensor 11 Example 2: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Declaring a variable let res1; // Calling tidy method const res2 = tf.tidy(() => { // Calling tf.keep() method with its // parameter res1 = tf.keep(tf.tensor1d( [1.3, 0.5, 0, NaN, null, -.5]).cos()); }); // Printing output res1.print(); Output: Tensor [0.2675007, 0.8775977, 1, NaN, 1, 0.8775977] Reference: https://js.tensorflow.org/api/latest/#keep Comment More infoAdvertise with us Next Article Tensorflow.js tf.keep() Function N nidhi1352singh Follow Improve Article Tags : JavaScript Web Technologies Tensorflow.js TensorFlow.js-Performance 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.pad() 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. 2 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.mean() 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.mean() function is used to calculate the mean value of the specified Tensor across its dimension. It reduces the given input el 2 min read Tensorflow.js tf.ones() Function Tensorflow.js is an open-source library for running machine learning models and deep learning neural networks in the browser or node environment. The tf.ones() function is used to create a new tensor where all elements are set to 1. Syntax: tf.ones(shape, dtype, name) Parameters: shape: It takes the 2 min read Like