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

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

Daidalos November 15, 2019

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()

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 ])


Links Site
Complex numbers usage in python stackoverflow
numpy.conj numpy doc
Mathematical functions for complex numbers python doc
Assigning complex values to numpy arrays? stackoverflow



Online visitors: Viewed: 589 Active: Nov. 15, 2019, 8:17 p.m. Comments: 0