Tensorflow.js tf.TensorBuffer Class .toTensor() Method Last Updated : 22 Apr, 2022 Summarize Comments Improve Suggest changes Share 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.TensorBuffer class .toTensor() function is used to create an immutable Tensor object from the specified buffer and its values. Syntax: toTensor () Parameters: This function does not accept any parameters. Return Value: It returns the created immutable Tensor object. 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 with // the help of .toTensor() function buffer.toTensor().print(); Output: Tensor [[5 , 0], [10, 0]] Example 2: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Creating a buffer of 3*3 dimensions const buffer = tf.buffer([3, 3]); // Setting values at particular indices. buffer.set(5, 0, 0); buffer.set(10, 0, 1); buffer.set(15, 1, 0); buffer.set(20, 1, 1); buffer.set(25, 2, 0); buffer.set(30, 2, 1); buffer.set(35, 2, 2); // Converting the above buffer back // to a tensor value to print with // the help of .toTensor() function buffer.toTensor().print() Output: Tensor [[5 , 10, 0 ], [15, 20, 0 ], [25, 30, 35]] Reference: https://js.tensorflow.org/api/latest/#tf.TensorBuffer.toTensor Comment More infoAdvertise with us Next Article Tensorflow.js tf.TensorBuffer Class .toTensor() Method K Kanchan_Ray Follow Improve Article Tags : JavaScript Web Technologies Tensorflow.js TensorFlow.js-Classes TensorFlow.js-Tensor +1 More Similar Reads 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 .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 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 con 2 min read Tensorflow.js tf.Tensor class .data() 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. 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.Tensor .toString() 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.tensor.toString() method is used to log the tensor in the human-readable form if you console.log() just tf.tensor then it will 2 min read Like