Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Tensorflow.js tf.real() Function

  • Last Updated : 20 May, 2021

Tensorflow.js is an open-source library that is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment.

The .real() function is used to find a tensor for the stated tensor input, which is of type float and is the real section of each element that is considered in input as a complex number.

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 :  

tf.real( input )

Parameters:  



  • input: It is the tensor input, which takes a complex number as an input.

Return Value: It returns the real section of a complex or a real tensor input.

Example 1: In this example, we are defining an input tensor of float type and then printing the real part of it. For creating an input tensor we are utilizing the .complex() method and in order to print the output we are using the .print() method.  

Javascript




// Defining input tensor
const y = tf.complex([-9.25, 12.25], [6.66, 8.66]);
  
// Calling real() function and
// printing the output
tf.real(y).print();

Output:

Tensor
    [-9.25, 12.25]

Example 2: In this example, we are using null, character, as well as integer type values as tensor input.

Javascript




// Defining input tensor
const y = tf.complex([null, 'a'], [5, 'r']);
  
// Calling real() function
var z = tf.real(y);
  
// Prints output
z.print();

Output:

Tensor
    [0, NaN]

In the above example, the null value returns zero and the character type value returns NaN.

Reference:https://js.tensorflow.org/api/latest/#real

My Personal Notes arrow_drop_up
Recommended Articles
Page :