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.

Syntax :  

tf.real( input )


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


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


    [-9.25, 12.25]

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


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


    [0, NaN]

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


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!