Sunday, November 17, 2024
Google search engine
HomeLanguagesJavascriptTensorflow.js tf.complex() Function

Tensorflow.js tf.complex() Function

Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. It helps developers to develop ML models in JavaScript, and use ML directly in the browser or in Node.js.

The tf.complex() function is used to convert two real numbers to a complex number.

Syntax:

tf.complex(real, imag)

Parameter:

  • real: It can be any of these three tf.Tensor, TypedArray, or Array. It represents the real part of the complex number formed.
  • imag: It can also be any of this three tf.Tensor, TypedArray, or Array. It represents the imaginary part of the complex number formed.

Return Value: It returns a tf.Tensor.

Note: The real parameter is the tf.Tensor represents the real part of the complex number and the imag parameter is the tf.Tensor represents the imaginary part of the complex number.
For example, 

  • Let real be [r0, r1, r2]
  • Let imag be [i0, i1, i2]
  • The converted complex number will be [r0 + i0, r1 + i1, r2 + i2]

Example 1:

Javascript




// The complex function containing the
// real and imag Typedarray
const complex = tf.complex ([5,3],[1,3]);
  
// Printing the tensor
complex.print();


Output:

Tensor
   [5 + 1j, 3 + 3j]

Example 2:

Javascript




// The complex function containing the
// real and imag Typedarray
const complex = tf.complex(
    tf.tensor1d([4.75, 5.75]),
    tf.tensor1d([2.25, 3.25])
);
  
// Printing the tensor
complex.print();


Output:

Tensor
   [4.75 + 2.25j, 5.75 + 3.25j]

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

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!

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments