简体   繁体   English

重复角度函数python

[英]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. 该函数正常工作,但是我想知道如何编码它,而不是说仅计算theta1 = 0和theta2 = 10度,我如何优化它以使其能够像从0开始一样执行几次,分别为10、10、20、20.30度,分别给出r1和ds。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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