Tensorflow.js tf.mean() Function Last Updated : 18 May, 2021 Comments Improve Suggest changes Like Article Like 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. The tf.mean() function is used to calculate the mean value of the specified Tensor across its dimension. It reduces the given input elements along the dimensions of axes. If the parameter "keepDims" is true, the reduced dimensions are retained with length 1 else the rank of Tensor is reduced by 1. If the axes parameter has no entries, it returns a Tensor with a single element with all reduced dimensions. Syntax: tf.mean (x, axis?, keepDims?) Parameters: This function accepts three parameters which are illustrated below: x: The input tensor for which mean value is being computed.axis: The specified dimension(s) to reduce. By default it reduces all dimensions. It is optional parameter.keepDims: If this parameter value is true, it retains reduced dimensions with length 1 else the rank of Tensor is reduced by 1. It is also optional parameter. Return Value: It returns a Tensor of mean value. Example 1: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Initializing a some tensors const a = tf.tensor1d([0, 1]); const b = tf.tensor1d([3, 5]); const c = tf.tensor1d([2, 4, 7]); // Calling the .mean() function over // the above tensors a.mean().print(); b.mean().print(); c.mean().print(); Output: Tensor 0.5 Tensor 4 Tensor 4.333333492279053 Example 2: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Initializing a some tensors const a = tf.tensor1d([0, 1]); const b = tf.tensor2d([3, 5, 2, 8], [2, 2]); const c = tf.tensor1d([2, 4, 7]); // Initializing a axis parameters const axis1 = -1; const axis2 = -2; const axis3 = 0; // Calling the .mean() function over // the above tensors a.mean(axis1).print(); b.mean(axis2, true).print(); c.mean(axis1, false).print(); b.mean(axis3, false).print(); Output: Tensor 0.5 Tensor [[2.5, 6.5],] Tensor 4.333333492279053 Tensor [2.5, 6.5] Reference:https://js.tensorflow.org/api/latest/#mean Comment More infoAdvertise with us Next Article Tensorflow.js tf.mean() Function K Kanchan_Ray Follow Improve Article Tags : JavaScript Web Technologies Tensorflow.js Similar Reads Tensorflow.js tf.min() 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.min() function is used to calculate the minimum value from the specified Tensor across its dimension. It reduces the given inpu 2 min read Tensorflow.js tf.moments() Function The tf.moments() is used to calculate the mean and variance of tensor passed as an argument in the function. The mean and variance are calculated by aggregating the contents of the tensor across the axes passed in parameters. Syntax: tf.moments(tensor, axis, keepdims)Parameters: This method accepts 2 min read Tensorflow.js tf.sum() 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.sum() function is used to calculate sum of the elements of a specified Tensor across its dimension. It reduces the given input 2 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.norm() 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.norm() function is used compute the norm of matrices, vectors, and scalar. This function can also compute several other vector 2 min read Like