Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Tensorflow.js tf.util.sizeFromShape() Function

  • Last Updated : 02 Jul, 2021

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.

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

Syntax :  



  • 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:


// 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



Example 2:


// 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]));




My Personal Notes arrow_drop_up
Recommended Articles
Page :