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
import * as tf from "@tensorflow/tfjs"
const tn = tf.tensor([5, 6, 3, 4]);
const res = await tn.array();
console.log(res)
|
Output:
5,6,3,4
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs"
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
Last Updated :
22 Apr, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...