Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptTensorflow.js tf.util.sizeFromShape() Function

Tensorflow.js tf.util.sizeFromShape() Function

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
 

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