简体   繁体   中英

repeat angular function python

  def ang(theta1,theta2,x1,x2,r,dens):
        theta = []
        r1 = []
        ds = []

       #note x1,x2 is input data

       theta = np.arctan2(x1,x2)
       ang_deg = (theta*180)/(np.pi)

       for i in range(len(ang_deg)):
            if theta1 <= ang_deg[i]<= theta2:
                r1.append(r[i])
                ds.append(dens[i])

       return 

This function is working OK but I would like to know how could I code it such that instead of say calculating for theta1 = 0 and theta2 =10 degrees only ,how can I optimize it such that can do it do it several times like from 0,10, then 10,20 then 20,30 degrees giving r1 and ds for each of this.

Thanks

You could always just create a different function:

def ang_multiple(theta1s, theta2s, x1, x2, r, dens):
   results = []
   for i, theta1 in enumerate(theta1s):
       results.append(ang(theta1, theta2s[i], x1, x2, r dens))
   return results

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM