NumPy conjugate(): Complex Arrays, Conj, and Hermitian Workflows

Quick answer: np.conjugate() changes the sign of the imaginary part of each complex value and leaves real values unchanged. np.conj() is an alias, and arrays also provide conj() and conjugate() methods. Use .conj().T for a conjugate transpose, and use the ufunc’s out argument when a reusable output array is appropriate.

Python Pool infographic showing NumPy complex value conjugate sign change conjugate transpose and output array
NumPy conjugate changes the sign of each imaginary part elementwise; use conj as its alias and .conj().T when a conjugate transpose is required.

numpy.conjugate() returns the complex conjugate of each element in an array. For a complex value such as 3 + 4j, the conjugate is 3 - 4j: the real part stays the same and the sign of the imaginary part changes.

Use NumPy conjugate operations when working with complex arrays, signal processing, Fourier transforms, Hermitian matrices, and complex inner products. The key choices are np.conjugate(x), its shorter alias np.conj(x), and array methods such as x.conj() or x.conjugate().

Basic NumPy conjugate example

Pass a scalar or array-like object to np.conjugate(). NumPy applies the operation element by element.

import numpy as np

z = np.array([1 + 2j, 3 - 4j, -5j])
print(np.conjugate(z))

The result has the same shape as the input. Values with positive imaginary parts become negative, values with negative imaginary parts become positive, and real-only values are unchanged.

np.conjugate(), np.conj(), and array methods

np.conj() is an alias for np.conjugate(). NumPy arrays also provide .conj() and .conjugate() methods.

import numpy as np

z = np.array([1 + 2j, 3 - 4j])

print(np.conjugate(z))
print(np.conj(z))
print(z.conjugate())
print(z.conj())

These forms are equivalent for normal NumPy arrays. Choose the style that makes the surrounding expression most readable. In numerical code, A.conj().T is a common compact form for the conjugate transpose of an array.

Python Pool infographic showing a complex array, real part, imaginary part, and NumPy conjugate
Complex values: A complex array, real part, imaginary part, and NumPy conjugate.

Use out for an existing output array

np.conjugate() is a ufunc, so it supports common ufunc parameters such as out. Use out when you want to write the result into an existing array.

import numpy as np

z = np.array([1 + 2j, 3 - 4j])
out = np.empty_like(z)

np.conjugate(z, out=out)
print(out)

This can reduce temporary allocations in tight numerical workflows. For most beginner code, assigning result = np.conjugate(z) is clearer.

Conjugate transpose for arrays

For a regular NumPy array, use A.conj().T or A.conjugate().T to compute the conjugate transpose.

import numpy as np

A = np.array([[1 + 2j, 3], [4j, 5 - 6j]])
hermitian = A.conj().T

print(hermitian)

The .T part transposes the axes, and .conj() flips the sign of the imaginary part. This is different from a plain transpose, which only swaps axes. For older numpy.matrix objects, NumPy documents matrix.H as the complex conjugate transpose, but regular arrays are preferred in most modern NumPy code.

Real arrays are unchanged

Conjugating real numbers returns the same values because there is no imaginary part to flip.

import numpy as np

x = np.array([1, 2, 3])
print(np.conjugate(x))

This is useful when writing generic code that may receive real or complex arrays. The same expression can safely handle both cases.

Python Pool infographic mapping a complex value through conjugate to a sign-flipped imaginary part
Flip imaginary: A complex value through conjugate to a sign-flipped imaginary part.

Complex inner products and vdot()

For complex vectors, be careful with dot products. NumPy’s vdot() conjugates the first argument before computing the dot product and flattens higher-dimensional arrays.

import numpy as np

a = np.array([1 + 2j, 3 + 4j])
b = np.array([5 + 6j, 7 + 8j])

print(np.vdot(a, b))

Use np.vdot() when that conjugating behavior is what you want. Use other NumPy linear algebra tools when you need matrix multiplication, axis-aware products, or a result that should not conjugate the first input.

When complex conjugates matter

Complex conjugates show up whenever a calculation needs magnitude, phase, or Hermitian structure. For a single complex number, multiplying a value by its conjugate removes the imaginary part and gives a real magnitude-squared value. For arrays, the same idea appears in signal energy, Fourier-domain calculations, and complex least-squares problems.

In linear algebra, the conjugate transpose is the operation used for Hermitian matrices and many complex inner products. That is why A.conj().T is a more precise habit than A.T when your data may be complex. If you are comparing floating-point results after complex calculations, see NumPy allclose() for tolerant equality checks.

Python Pool infographic comparing conjugate, transpose, conjugate transpose, and Hermitian matrix
Hermitian workflow: Conjugate, transpose, conjugate transpose, and Hermitian matrix.

Common mistakes

Do not confuse A.T with A.conj().T. For real arrays they match, but for complex arrays they are different.

Do not assume np.conjugate() changes an array in place. It returns a result unless you provide out. Also remember that Python complex numbers use j, not i, for the imaginary unit.

If your calculation involves singular matrices or unstable linear algebra, see LinAlgError: Singular Matrix in Python and NumPy.

Official references

The examples here follow the NumPy documentation for numpy.conjugate(), numpy.conj(), ndarray.conjugate(), matrix.H, and numpy.vdot().

Conclusion

Use np.conjugate() or np.conj() to flip the sign of the imaginary part element-wise. Use A.conj().T for a conjugate transpose of regular arrays, and use np.vdot() when you specifically want the first vector conjugated in a complex inner product.

Apply Conjugation Elementwise

The conjugate operation works on scalars and arrays. The result keeps the input shape and dtype rules, so inspect the values when a pipeline mixes real and complex arrays.

import numpy as np

values = np.array([1 + 2j, 3 - 4j, 5])
result = np.conjugate(values)
print(result)
print(result.shape)
print(np.conj is np.conjugate)

Build A Conjugate Transpose

A transpose changes axes, while conjugation changes the sign of imaginary parts. A Hermitian or conjugate transpose needs both operations, commonly written array.conj().T for a two-dimensional array.

import numpy as np

matrix = np.array([[1 + 2j, 3], [4j, 5 - 1j]])
hermitian = matrix.conj().T
print(hermitian)
print(np.array_equal(hermitian, np.conjugate(matrix).T))
Python Pool infographic testing real values, zero imaginary parts, arrays, dtype, and products
Complex checks: Real values, zero imaginary parts, arrays, dtype, and products.

Write Into An Existing Output

NumPy ufuncs accept out when the result should be written into an existing array. This can reduce temporary allocations in a repeated numerical workflow, but the output shape must be compatible with the broadcasted input.

import numpy as np

values = np.array([1 + 2j, 3 - 4j])
out = np.empty_like(values)
np.conjugate(values, out=out)
print(out)

Check Real Data And Complex Math

Conjugating a real array leaves its values unchanged. In a complex calculation, make the conjugation explicit when it represents a mathematical operation such as an inner product or a Hermitian matrix, instead of assuming transpose alone is enough.

import numpy as np

real = np.array([1.0, 2.0])
vector = np.array([1 + 2j, 2 - 1j])
print(np.conjugate(real))
inner = np.sum(np.conjugate(vector) * vector)
print(inner)

NumPy documents conjugate() as an elementwise ufunc with out and where support, and the ndarray.conjugate() method refers to the same operation. Related references include dot products, complex angles, and numerical comparison.

For related complex-array calculations, compare dot products, complex angles, and allclose() when validating conjugated numerical results.

Frequently Asked Questions

What does NumPy conjugate() do?

It returns the complex conjugate elementwise, keeping each real part and changing the sign of each imaginary part.

Is np.conj() different from np.conjugate()?

No. np.conj is an alias for np.conjugate, and ordinary NumPy arrays also provide conj() and conjugate() methods.

How do I compute a conjugate transpose?

For a two-dimensional array, use array.conj().T or np.conjugate(array).T, depending on which expression is clearer in context.

Can conjugate write into an existing array?

Yes. Pass an appropriately shaped out array to the ufunc when you want the result stored without allocating a new output array.

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted