How to get the conjugate of a complex number in python ?

Published: November 15, 2019

DMCA.com Protection Status

Examples of how to get the conjugate of a complex number z in python:

Get the conjugate of a complex number

A solution is to use the python function conjugate(), example

>>> z = complex(2,5)
>>> z.conjugate()
(2-5j)
>>>

Matrix of complex numbers

Another example using a matrix of complex numbers

import numpy as np
>>> Z = np.random.random(10) + np.random.random(10) * 1j
>>> Z
array([ 0.07062625+0.88227272j,  0.34682234+0.65946885j,
        0.92763215+0.86887474j,  0.86426062+0.73231969j,
        0.58372574+0.1017348j ,  0.72396286+0.92159865j,
        0.27617746+0.96721269j,  0.22302559+0.09493447j,
        0.49912649+0.03699016j,  0.06242473+0.3835314j ])
>>> Z.conjugate()
array([ 0.07062625-0.88227272j,  0.34682234-0.65946885j,
        0.92763215-0.86887474j,  0.86426062-0.73231969j,
        0.58372574-0.1017348j ,  0.72396286-0.92159865j,
        0.27617746-0.96721269j,  0.22302559-0.09493447j,
        0.49912649-0.03699016j,  0.06242473-0.3835314j ])

References