Wednesday, October 22, 2025
HomeLanguagesJavascriptTensorflow.js tf.Tensor class .bufferSync() Method

Tensorflow.js tf.Tensor class .bufferSync() 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.Tensor class.bufferSync() method is used to return a tf.TensorBuffer that holds the underlying data.

Syntax:

bufferSync()

Parameters:

  • It takes no parameters

Return Value: It returns tf.TensorBuffer

Example 1:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
console.log(tf.tensor([1, 3, 5, 4, 2]).bufferSync())


Output:

{
  "dtype": "float32",
  "shape": [
    5
  ],
  "size": 5,
  "values": {
    "0": 1,
    "1": 3,
    "2": 5,
    "3": 4,
    "4": 2
  },
  "strides": []
}

Example 2:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
const a= tf.tensor2d([[0, 1], [2, 3]])
console.log(a.bufferSync())


Output:

{
  "dtype": "float32",
  "shape": [
    2,
    2
  ],
  "size": 4,
  "values": {
    "0": 0,
    "1": 1,
    "2": 2,
    "3": 3
  },
  "strides": [
    2
  ]
}

Reference: https://js.tensorflow.org/api/latest/#tf.Tensor.bufferSync

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS