# Why is numpy.angle returning values on real numbers?

This question is a follow up on previous. As I am analyzing the sampled data I need to know if it is complex or real. This is important for me since I want to transform my two-sided to a one-sided PSD. Then I have to either divide the spectrum by $$N/2$$ (for real-valued signals) or $$N$$ (for complex-valued signals).

So far I executed both np.angle(x.MIC, deg=True) and np.iscomplexobj(x.MIC) with the returned value of array([180., 180., 180., ..., 180., 180., 0.]) and False respectively.

Why do I keep getting this inconsistency in my results? Am I missing something important here?

• ??? You have the time data… Does x.MIC have real or complex values?!
– Jdip
Oct 30, 2023 at 16:21
• @Jdip complex values are not present, but angles are. How can it be real if there are angles?
– Tom
Oct 30, 2023 at 16:28
• Ok, I agree it’s a little confusing. I wrote an answer explaining the behavior.
– Jdip
Oct 30, 2023 at 17:36

np.angle(z) with z = a + bi uses arctan2(a,b),

which returns the signed angle in radians between the ray ending at the origin and passing through the point (1,0), and the ray ending at the origin and passing through the point (b, a).

In your case, b = 0 so np.angle() is returning arctan2(a,0).

• If a > 0, that means a lies on the positive x-axis of the unit circle, and the angle between the positive x-axis and the line connecting a and the origin $$(0,0)$$ is 0.

• If a < 0, that means a lies on the negative x-axis of the unit circle, and the angle between the positive x-axis and the line connecting a and the origin $$(0,0)$$ is pi.

Since you're asking for degrees, it multiplies the values by 180/pi, so the final result is either 0 for positive real numbers or 180 for negative real numbers.

• That solves my question. Thank you!
– Tom
Oct 31, 2023 at 6:56