Actually, none of the proposed solutions worked in my case (Python 2.7.6, NumPy 1.8.2). But I've found out, that change of dtype from complex (standard Python library) to numpy.complex_ may help:

>>> import numpy as np
>>> x = 1 + 2 * 1j
>>> C = np.zeros((2,2),dtype=np.complex_)
>>> C
array([[ 0.+0.j,  0.+0.j],
       [ 0.+0.j,  0.+0.j]])
>>> C[0,0] = 1+1j + x
>>> C
array([[ 2.+3.j,  0.+0.j],
       [ 0.+0.j,  0.+0.j]])
Answer from Lenka42 on Stack Overflow
🌐
GitHub
github.com › numpy › numpy › issues › 16039
Efficient way to create a complex array from two real arrays · Issue #16039 · numpy/numpy
April 22, 2020 - Dear NumPy developers, This may be more like a question. I have two real arrays (a and b), and I would like create a complex array (c) which takes the two real arrays as its real and imaginary parts respectively. The simplest one would b...
Author   zhcui
🌐
Python.org
discuss.python.org › ideas
Complex numbers support in array module - Ideas - Discussions on Python.org
March 7, 2023 - I know about numpy, but I would really like to see it in the built-in python module, but I was wondering if this could be a thing. Any thoughts about this?
🌐
YouTube
youtube.com › watch
How to create an array of complex numbers in Python - YouTube
How to create an array of complex numbers in Python
Published   July 4, 2021
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.array.html
numpy.array — NumPy v2.4 Manual
>>> np.array([1, 2, 3], dtype=complex) array([ 1.+0.j, 2.+0.j, 3.+0.j]) Data-type consisting of more than one element: >>> x = np.array([(1,2),(3,4)],dtype=[('a','<i4'),('b','<i4')]) >>> x['a'] array([1, 3], dtype=int32) Creating an array from sub-classes: >>> np.array(np.asmatrix('1 2; 3 4')) array([[1, 2], [3, 4]]) >>> np.array(np.asmatrix('1 2; 3 4'), subok=True) matrix([[1, 2], [3, 4]]) Limiting the maximum dimensions with ndmax: >>> a = np.array([[1, 2], [3, 4]], dtype=object, ndmax=2) >>> a array([[1, 2], [3, 4]], dtype=object) >>> a.shape (2, 2) >>> b = np.array([[1, 2], [3, 4]], dtype=object, ndmax=1) >>> b array([list([1, 2]), list([3, 4])], dtype=object) >>> b.shape (2,) Go BackOpen In Tab ·
🌐
GeeksforGeeks
geeksforgeeks.org › extracting-the-real-and-imaginary-parts-of-an-numpy-array-of-complex-numbers
Extracting the real and imaginary parts of an NumPy array of complex numbers - GeeksforGeeks
September 2, 2020 - Example: If there are odd numbers in an array. A = [1,2,3,4,5,6,7] Then the median element will be 7+1/2= 4th el ... In this article, we will discuss how to return real parts if the input is complex with all imaginary parts close to zero in Python. The numpy np.real_if_close() method is used to return the real parts if the input is a complex number with all imaginary parts close to zero.
🌐
IncludeHelp
includehelp.com › python › numpy-creating-a-complex-array-from-2-real-ones.aspx
Python - NumPy: Creating a complex array from 2 real ones?
# Import numpy import numpy as np # Import pandas import pandas as pd # Creating two numpy arrays arr1 = np.array([15, 25, 30]) arr2 = np.array([5, 15, 20]) # Display original arrays print("Original array 1:\n",arr1,"\n") print("Original array 2:\n",arr2,"\n") # Creating a complex array com = np.empty((3,3),dtype=np.complex128) com.real = arr1 com.imag = arr2 # Display result print("Result:\n",com)
Find elsewhere
🌐
w3resource
w3resource.com › python-exercises › numpy › python-numpy-exercise-15.php
NumPy: Find the real and imaginary parts of an array of complex numbers - w3resource
August 29, 2025 - Write a NumPy program to find the real and imaginary parts of an array of complex numbers · Sample Solution: Python Code: # Importing the NumPy library with an alias 'np' import numpy as np # Calculating square root of a complex number x = np.sqrt([1 + 0j]) # Calculating square root of another complex number y = np.sqrt([0 + 1j]) # Printing the original array 'x' and 'y' print("Original array:x ", x) print("Original array:y ", y) # Printing the real part of the array 'x' and 'y' print("Real part of the array:") print(x.real) print(y.real) # Printing the imaginary part of the array 'x' and 'y'
🌐
Moonbooks
moonbooks.org › Articles › How-to-create-a-matrix-of-complex-numbers-in-python-using-numpy-
How to create a matrix of complex numbers in python using numpy ?
November 15, 2019 - Examples of how to create a matrix of complex numbers in python using numpy: Table of contents · Create a matrix of random numbers · Create a matrix of random numbers with 0+0j · Create a matrix of random complex numbers · References · >>> Z = np.array([[1+2j,1+3j],[5+6j,3+8j]]) >>> Z array([[ 1.+2.j, 1.+3.j], [ 5.+6.j, 3.+8.j]]) >>> import numpy as np >>> Z = np.zeros(10, dtype=complex) >>> Z array([ 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j]) Another example ·
🌐
TutorialsPoint
tutorialspoint.com › article › extracting-the-real-and-imaginary-parts-of-a-numpy-array-of-complex-numbers
Extracting the real and imaginary parts of a NumPy array of complex numbers
July 10, 2023 - In Python, we can extract the real and imaginary parts of a NumPy array of the complex number using the real and imag attributes of the array, respectively. Numpy is a Python library that is used for complex calculations and also provides support ...
🌐
SciPy
docs.scipy.org › doc › › numpy-1.13.0 › reference › generated › numpy.array.html
numpy.array — NumPy v1.13 Manual
>>> np.array([1, 2, 3], dtype=complex) array([ 1.+0.j, 2.+0.j, 3.+0.j]) Data-type consisting of more than one element: >>> x = np.array([(1,2),(3,4)],dtype=[('a','<i4'),('b','<i4')]) >>> x['a'] array([1, 3]) Creating an array from sub-classes: >>> np.array(np.mat('1 2; 3 4')) array([[1, 2], [3, 4]]) >>> np.array(np.mat('1 2; 3 4'), subok=True) matrix([[1, 2], [3, 4]]) numpy.full_like ·
🌐
GeeksforGeeks
geeksforgeeks.org › complex-numbers-in-python-set-1-introduction
Complex Numbers in Python | Set 1 (Introduction) - GeeksforGeeks
August 21, 2024 - 2. log(x ... Other than some generic containers like lists, Python in its definition can also handle containers with specified data types. The array can be handled in Python by a module named "array".
🌐
Medium
medium.com › @whyamit404 › working-with-complex-numbers-in-numpy-c3eae8876a88
Working with Complex Numbers in NumPy | by whyamit404 | Medium
February 8, 2025 - So, how do you create complex numbers? It’s simple. You can use numpy.array() to create an array of complex numbers, just like any other NumPy array.
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.imag.html
numpy.imag — NumPy v2.4 Manual
If val is real, the type of val is used for the output. If val has complex elements, the returned type is float. ... Try it in your browser! >>> import numpy as np >>> a = np.array([1+2j, 3+4j, 5+6j]) >>> a.imag array([2., 4., 6.]) >>> a.imag = np.array([8, 10, 12]) >>> a array([1.
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.real.html
numpy.real — NumPy v2.4 Manual
If val has complex elements, the returned type is float. ... Try it in your browser! >>> import numpy as np >>> a = np.array([1+2j, 3+4j, 5+6j]) >>> a.real array([1., 3., 5.]) >>> a.real = 9 >>> a array([9.+2.j, 9.+4.j, 9.+6.j]) >>> a.real = np.array([9, 8, 7]) >>> a array([9.+2.j, 8.+4.j, 7.+6.j]) >>> np.real(1 + 1j) 1.0