Home > Back-end >  How do I get the imaginary part in Python?
How do I get the imaginary part in Python?

Time:03-10

How do I get the imaginary (or real part) of an array ?#

Good Morning fellas, I have trouble with my N qubit wavefunction. I try to prepare a state psi = a|0> b*exp(2i\pi\theta)|1>, and i wanted to check if the values for b*exp(2i\pi\theta) were well distributed.

Here is how I got my wavefunction :

N = 100
psi = np.full([100, 2], None)
for i in range(N) :
x = np.random.random()
y = y = np.exp(2j*np.pi*np.random.random())*np.sqrt(1-x**2)
psi[i] = [x,y]

I then used this line to get an array with only the y's and tried to plot them on the complex plane :

psi2 = psi[:,1]
plt.plot(psi2.real,psi2.imag)

I can't grasp why it doesn't plot the imaginary part and i just get :

enter image description here

  • Related