Complete the code to create a complex number using numpy.
import numpy as np z = np.[1](3 + 4j) print(z)
The np.complex function creates a complex number in numpy.
Complete the code to get the imaginary part of a numpy complex number.
import numpy as np z = np.complex(2 + 5j) imag_part = z[1] print(imag_part)
The .imag attribute gives the imaginary part of a complex number.
Fix the error in the code to correctly create a numpy complex number from real and imaginary parts.
import numpy as np real = 1 imag = 2 z = np.complex([1] + [2]j) print(z)
To create a complex number from parts, add real part plus imaginary part times j.
Fill both blanks to create a numpy array of complex numbers from two lists of real and imaginary parts.
import numpy as np real_parts = [1, 2, 3] imag_parts = [4, 5, 6] complex_array = np.array([[1] + [2]j for [3] in range(3)]) print(complex_array)
We use list comprehension with index i to combine real and imaginary parts into complex numbers.
Fill all three blanks to create a dictionary mapping complex numbers to their magnitudes.
import numpy as np complex_nums = [1+1j, 2+2j, 3+3j] magnitudes = [1]: np.[2]([3]) for [4] in complex_nums}} print(magnitudes)
We create a dictionary where keys are complex numbers and values are their magnitudes using np.abs.