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 (...locations)
Parameters: This method accepts single parameter which is illustrated below:
- locations: The specified location indices.
Return Value: It returns the value at the specified location indices.
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); // 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:
5 10
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); // Getting the values for the // specified indices with // the help of .get() functions console.log(buffer.get(0, 0)); console.log(buffer.get(0, 1)); console.log(buffer.get(1, 0)); console.log(buffer.get(2, 0)); console.log(buffer.get(2, 1)); console.log(buffer.get(2, 2)); |
Output:
5 10 15 25 30 35
Reference: https://js.tensorflow.org/api/latest/#tf.TensorBuffer.get
Contact Us