Tensorflow.js tf.buffer() 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.buffer() function is used to create an empty Tensor Buffer for the specified data type and shape. The values are set in the created buffer using buffer.set() function. Syntax: tf.buffer (shape, dtype, values) Parameters: This function accepts three parameters which are illustrated below: shape: An array of integers which defines the shape of output tensor.dtype: The data type of the created buffer. It's defaults value is 'float32'. This parameter is optional.values: The values for the created buffer. It's default values is zeros. This parameter is optional. Return Value: This function does not return any values as it create the buffer only. Example 1: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Creating a buffer of [2, 2] shape const buffer = tf.buffer([2, 2]); // Getting the created buffer in the // form of Tensor of zeros values // as no values are set in the buffer buffer.toTensor().print(); Output: Tensor [[0, 0], [0, 0]] Example 2: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Creating a buffer of [3, 3] shape const buffer = tf.buffer([3, 3]); // Setting values in the created buffer // at particular indices buffer.set(10, 2, 0); buffer.set(15, 0, 1); buffer.set(20, 1, 2); // Getting the buffer in the form of Tensor // along with the set values buffer.toTensor().print(); Output: Tensor [[0 , 15, 0 ], [0 , 0 , 20], [10, 0 , 0 ]] Reference: https://js.tensorflow.org/api/latest/#buffer Comment More infoAdvertise with us Next Article Tensorflow.js tf.buffer() Function K Kanchan_Ray Follow Improve Article Tags : JavaScript Web Technologies Tensorflow.js Similar Reads Tensorflow.js tf.eye() Function Tensorflow.js is an open-source library for creating machine learning models in Javascript that allows users to run the models directly in the browser. The tf.eye() is a function defined in the class tf.Tensor. Itâs used to create an identity matrix of specified rows and columns. An identity matrix 3 min read Tensorflow.js tf.env() 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 .env() function is used to return the present environment i.e. a global entity. Moreover, the environment object in 1 min read Tensorflow.js tf.fetch() 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 .fetch() function is used to return a platform dedicated operation of fetch. Moreover, in case fetch is specified i 1 min read Tensorflow.js tf.elu() Function Tensorflow.js is an open-source library that is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .elu() function is used to find the exponential linear of the stated tensor input and is done elements wise. 2 min read Tensorflow.js tf.fill() Function Tensorflow.js is an open-source library for creating machine learning models in Javascript that allows users to run the models directly in the browser. The tf.fill() is a function defined in the class tf.Tensor. It is used to create a tensor that is filled with a scalar value. Syntax: tf.fill( shape 2 min read Like