NumPy stands for Numerical Python and provides a number of mathematical operations to operate on multidimensional matrices and arrays. This open-source package enables you to perform a wide variety of complex mathematical operations on arrays or matrices.

**Also read: Numpy Heaviside – Compute the Heaviside step function**

One such mathematical function to work on arrays or matrices with complex numbers is the `conjugate()`

function. In this article let’s try to understand this function, its syntax, and its implementation in Python.

## What is the conjugate() function used for?

This function is used to return a complex conjugate, which is a complex number that has the same real portion as the original complex number, and an imaginary part with the same magnitude but a different sign. When a complex number is multiplied by its complex conjugate, a real number is obtained. The output returned is in an element-by-element manner for a given input array of complex numbers.

```
Example:
Complex Number -> a + ib
Complex Conjugate -> a - ib
```

### Syntax

```
numpy.conjugate(x, /, out=None, *, where=True, order='K', dtype=None)
```

**x**: array_like,*Required*- Input value/s.

**out**: n-dimensional array, None, or tuple,*optional*- a place where the outcome is saved. It must have a shape that the inputs broadcast to if it is provided. A newly allocated array is returned in the absence of any input or None. The length of a tuple must match the number of outputs.

**where:**array_like,*optional*- This circumstance is announced over the input. The ufunc result will be set to the out array at points where the condition is True. The out array will keep its initial value in all other places. It should be noted that places within an uninitialized out array formed with the default out=None will continue to be uninitialized if the condition is False.

****kwargs**, Optional- For other keyword-only arguments

**order:**{‘C’, ‘F’, ‘A’, or ‘K’},*optional*- Changes the result’s memory layout. “C” stands for C-order, “F” for F-order, and “A” stands for “C” unless “a” is Fortran contiguous. “K” denotes a layout that closely resembles “a”.

**dtype:**data-type,*optional*- Overrides the data type of the result.

## Implementing the conjugate() function

Make sure to import the NumPy package in your IDE before implementing the function. To do so run the following line of code in your IDE.

```
import numpy as np
```

*NOTE:*`conj()`

is shorthand or alias for `conjugate()`

function in NumPy.

```
#checking if both functions are same or not
np.conjugate is np.conj
#both function works the same ways
x = np.conjugate(1 + 3j)
y = np.conj(1 + 3j)
print(x,"\n",y)
```

### Example 1: Complex Number as Input

```
x = 2 + 3j
np.conjugate(x)
x1 = 2 - 5j
np.conjugate(x1)
```

**Output**

### Example 2: Array of complex numbers as input

```
#creating an array
x = (1 + 2j, 2 - 3j, 4 - 2j)
y = np.conjugate(x)
print("input ",x,"\n\noutput ",y)
```

**Output**

### Example 3: n-dimensional matrix of a complex number as input

```
#creating matrix
x = np.identity(3,dtype=complex)
y = np.conjugate(x)
print("input ",x,"\n\noutput ",y)
```

**Output**

In this example, `identity()`

function is used to create an n-dimensional identity matrix of a complex number.

## Summary

In conclusion, NumPy offers many efficient mathematical functions to work on arrays and multi-dimensional matrices. One such function conjugate() is discussed in this article, it works on complex numbers and returns a complex conjugate of the input value.

## References

https://numpy.org/doc/stable/reference/generated/numpy.conjugate.html