0

Consider the example:

x = np.array([-6,-5,-4,-3,-2,-1,0,1,2,3,5,6])
x % (2 * np.pi)

This modulo operation will map the intervall x to [0,2pi].

If i replace 2pi by pi or -pi i get the following result:

array([0.28318531, 1.28318531, 2.28318531, 0.14159265, 1.14159265,
   2.14159265, 0.        , 1.        , 2.        , 3.        ,
   1.85840735, 2.85840735])    # for pi

array([-2.85840735, -1.85840735, -0.85840735, -3.        , -2.        ,
   -1.        , -0.        , -2.14159265, -1.14159265, -0.14159265,
   -1.28318531, -0.28318531]) # for - pi

Which is not correct.

Does someone know an easy way to map x to [-pi,pi]?

Heißenberg93
  • 1,829
  • 3
  • 11
  • 10

1 Answers1

0

I think that's because python modulo % returns a result having the same sign as the denominator (pi and -pi in your case).

  • Yeah i thought so to. Do u know an easy way to map x to [-pi ,pi]? – Heißenberg93 Nov 18 '19 at 11:04
  • mapping a range of values to another is already solved in this question https://stackoverflow.com/questions/1969240/mapping-a-range-of-values-to-another, otherwise please explain what do you mean exactly by mapping –  Nov 18 '19 at 13:34