Tensorflow.js is an open-source library that is being develop by Google for running machine learning models as well as deep learning neural networks in the browser or node environment.
The .util.sizeFromShape() function is used to find the number of elements i.e. the size of the stated tensor input from the stated shape.
Syntax :
tf.util.sizeFromShape(shape)
Parameters:
- shape: It is the stated shape whose size is to be returned. It is of type number[].
Return Value: It returns a number.
Example 1:
Javascript
// Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Defining shape const sh = [5, 8, 1]; // Calling tf.util.sizeFromShape() method const num = tf.util.sizeFromShape(sh); // printing output console.log(num); |
Output:
40
Example 2:
Javascript
// Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Calling tf.util.sizeFromShape() method and // printing output console.log(tf.util.sizeFromShape([1.4, 5.6, 9.0])); |
Output:
70.55999999999999
Reference:https://js.tensorflow.org/api/1.0.0/#sizeFromShape