# Tensorflow.js tf.complex() Function

• Last Updated : 20 May, 2021

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.

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.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]```
My Personal Notes arrow_drop_up