Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment.
The .imag() function is used to find the imaginary section of the stated complex or a real tensor input. Moreover, if the stated tensor input is real then there is no imaginary part, so tensor of all zeroes is returned as output.
Syntax :
tf.imag(input)
Parameters:
- input: It is the stated tensor input, and it can be of type tf.Tensor, TypedArray, or Array.
Return Value: It returns the tf.Tensor object.
Example 1:
Javascript
// Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Defining tensor input elements const y = tf.complex([-21, 30], [14, 5]); // Calling imag() method and // Printing output tf.imag(y).print(); |
Output:
Tensor [14, 5]
Example 2:
Javascript
// Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Calling imag() method and // Printing output tf.imag(tf.complex([-2.1, 3.0], [1.65, 57.5])).print(); |
Output:
Tensor [1.65, 57.5]
Reference: https://js.tensorflow.org/api/latest/#imag