 # Exercise l.1.1 in the codebook exercise section

I am unable to use np.linalg.norm() or np.angle() function to normalize the complex state vector coefficients. Is there any other way to solve it?

Hi @Tejas_Limaye, welcome to the forum!

You can in fact use `np.linalg.norm()`. Remember though that this function gives you the norm of a vector, but it doesn’t normalize it. For example: the norm of the vector [2,0] is 2 so `np.linalg.norm()` will return the integer 2. The question instead asks you to return the normalized vector, so in this example you should return [1,0].

Please let me know if this helps you!

Even after writing this code I’m unable to get the output. What is the error here?

Great question @Tejas_Limaye!

Note that we get a normalized quantum state when a’^2+b’^2 = 1. Here we’re normalizing the quantum state [a’,b’]. Notice that this is not the same as saying a’^2 = 1 and b’^2 = 1. In fact, if this happens we would get a’^2+b’^2 = 2.

Let’s test your code with some random example.
Let’s say that alpha = 0.2 and beta = 2.
a1 = 0.2 and a2 = 2.
Now, ans1 = 0.2/0.2 = 1 and ans2 = 2/2=1.
So in fact ans1^2 + ans2^2 = 2

I hope this helps you understand your error and find the correct solution!

That helps a lot, thanks Catalina