. Advertisement .

..3..

. Advertisement .

..4..

Python is a powerful language for working with numbers. It also allows you to work with both real and imaginary numbers. A complex or imaginary number is a real number multiplied by an imaginary unit.

This article will discuss solutions for the “**Imaginary Numbers In Python”. **Now let’s get started.

## What is Complex Numbers in Python?

Not just the real number, Python is also able to handle complicated numbers and the associated functions by using”cmath” as a file “cmath”. Complex numbers are used in numerous applications that involve mathematics , and python offers useful tools to manipulate and handle these numbers.

For example, when converting real figures to complex one how it is. Complex numbers are represented as “ **x + yi** “. Python transforms the real number x as well as into complex numbers using this function **complex(x,y)**. The real portion can be access by through the program **() and the real()** and imaginary part can be represented with **Imag()**.

**The Effective Methods For The “Imaginary Numbers In Python”.**

Complex numbers have one real and an imaginary component. In Python, the imaginary part is expressed by appending a j or J to the number.

A complex number can be easily generated by directly assigning the real and imaginary parts to a variable. The following Python code demonstrates how to generate a complex number:

```
a = 8 + 5j
print(type(a))
```

Output:

`<class 'complex'>`

**Solution 1: Use the numpy.array()**

NumPy is an acronym which stands for Numerical Python. It is a Python library that deals with arrays and provides functions for operating on these arrays. As the name implies, the numpy.array() function is usually used to create an array.

You can print using numpy.array(). Let us learn more about this by using the following example:

```
import numpy as np
arr = np.array([9+6j,5+6j,5+2j])
print(arr)
```

Output:

`[9.+6.j 5.+6.j 5.+2.j]`

**Solution 2: Use the mathematical operation**

By using mathematical operations you can print imaginary numbers. Lets learn about of this by given below example:

```
a = 9 + 8j
b = 6 + 3j
c = (a.imag + b.imag)
print(c)
print('after multiplication = ', a*b)
```

Output:

```
11.0
after multiplication = (30+75j)
```

**Solution 3: Use the complex()**

To convert the two given real numbers into a complex number, we can also use the built-in complex() function.

```
a = 8
b = 5
c = complex(8,5)
print(type(c))
```

Output:

`<class 'complex'>`

**Conclusion**

Python is a language with a very bright appearance, clear structure, convenient for beginners, and easy to learn; widely used in artificial intelligence development. Python’s structure also allows users to write code with minimal keystrokes.

Those simple approaches presented above are simple solutions to the “**Imaginary Numbers In Python**“.

Please leave all your concerns in the comments section if you have any further questions. I wish you all an effective day with your tool.

## Leave a comment