Tensorflow.js tf.TensorBuffer Class Last Updated : 08 Jul, 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. This TensorBuffer class mutable object is similar to tf.Tensor which permits users to set values at the specified locations before converting to an immutable tf.Tensor. For creating a tensor buffer, tf.buffer() is used. This TensorBuffer class is having three inbuilt functions which are illustrated below: tf.TensorBuffer class .set() functiontf.TensorBuffer class .get() functiontf.TensorBuffer class .toTensor() function The tf.TensorBuffer class .set() function is used to sets a given value in the buffer at a specified location. Example 1: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Creating a buffer of 2*2 dimensions const buffer = tf.buffer([2, 2]); // Setting values at particular indices. buffer.set(5, 0, 0); buffer.set(10, 1, 0); // Converting the above buffer // back to a tensor value to print buffer.toTensor().print(); Output: Tensor [[5 , 0], [10, 0]] The tf.TensorBuffer class .get() function is used to return the value in the specified buffer for the given location. Example 2: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Creating a buffer of 2*2 dimensions const buffer = tf.buffer([2, 2]); // Setting values at particular indices. buffer.set(5, 0, 0); buffer.set(10, 1, 0); // Getting the values for the // specified indices with the // help of .get() function console.log(buffer.get(0, 0)); console.log(buffer.get(1, 0)); Output: The tf.TensorBuffer class .toTensor() function is used to create an immutable Tensor object from the specified buffer and its values. 5 10 Example 3: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Creating a buffer of 2*2 dimensions const buffer = tf.buffer([2, 2]); // Setting values at particular indices. buffer.set(5, 0, 0); buffer.set(10, 1, 0); // Converting the above buffer // back to a tensor value to print // with the help of .toTensor() function buffer.toTensor().print(); Output: Tensor [[5 , 0], Reference: https://js.tensorflow.org/api/latest/#class:TensorBuffer Comment More infoAdvertise with us Next Article Tensorflow.js tf.TensorBuffer Class K Kanchan_Ray Follow Improve Article Tags : JavaScript Web Technologies Tensorflow.js Similar Reads Tensorflow.js tf.Tensor Class 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. A tf.Tensor object represents an immutable, multidimensional array of numbers that has a shape and a data type. Tensors are the core d 4 min read Tensorflow.js tf.TensorBuffer class .get() Method 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.TensorBuffer class .get() method is used to return the value in the specified buffer for the given location. Syntax: get (...lo 2 min read Tensorflow.js tf.TensorBuffer Class .set() Method 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.TensorBuffer class .set() function is used to set a given value in the buffer at a specified location. Syntax: set (value, ...l 2 min read Tensorflow.js tf.TensorBuffer Class .toTensor() Method 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.TensorBuffer class .toTensor() function is used to create an immutable Tensor object from the specified buffer and its values. 2 min read Tensorflow.js tf.LayersModel Class 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. Tensorflow. js tf.LayerModel class is used to training, interface and evaluation of model. It have many method for training, evaluatio 2 min read Like