top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Python: scalar vs array and program control

0 votes
73 views

I'm fairly new to Python, struggling to write in a more object-oriented, functional style. I just wrote a function that takes two arrays
representing sine (y) and cosine (x) angle coordinates, and returns the angle in degrees. I had initially written the function to take
array-like arguments x/y, but I'd like to generalize and take scalars as well. However, the function has a subsetting operations, which don't work with scalars:

 vmag = np.sqrt((x ** 2) + (y ** 2))
 ang = np.arctan2(y, x)
 ang[ang < 0] = ang[ang < 0] + (2 * np.pi) # output range 0 - 2*pi
 ang[vmag == 0] = 0 # when magnitude is 0 the angle is also 0
 ang[ang == 0] = 2 * np.pi # convention

If I want to take scalars x/y, I naively thought about implementing an if/else statement right before the subsetting operations. However, my intuition tells me there must be a proper object-oriented solution to this. Any tips appreciated.

posted Jul 25, 2015 by anonymous

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button

Similar Questions
+2 votes

Below instruction will start CPU stress with maximum of 100%,

while(1);

Below instructions will start CPU stress with near to 0%.

while(1)
     sleep(1);

Is there any way to control this? I mean what if i want to start CPU stress of >100% and what if want to start CPU stress with particular number?

Can any one help in programming that? I am looking for C/C++/Python solution on Linux...

...