Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptTensorflow.js tf.Tensor class .array() Method

Tensorflow.js tf.Tensor class .array() 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 .array() method is used to return the tensor input like a nested array. Moreover, the relocation of data is made asynchronously.

Syntax:

array()

Parameters: This method does not hold any parameters.

Return Value: It returns the promise of number[].

Example 1:

Javascript




// Importing tensorflow library
import * as tf from "@tensorflow/tfjs"
  
// Creating a tensor
const tn = tf.tensor([5, 6, 3, 4]);
  
// Calling array() method
const res = await tn.array();
  
// Printing output
console.log(res)


Output:

5,6,3,4

Example 2:

Javascript




// Importing tensorflow library
import * as tf from "@tensorflow/tfjs"
  
// Calling array() method and
// Printing output
console.log(await tf.tensor2d([1.7, 3.7, 9.7, null], [4, 1]).array());


Output:

1.7000000476837158,3.700000047683716,9.699999809265137,0

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

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

Recent Comments