Is there any way to keep a character constant in numerical calculations in python?

Viewed 27

I am performing some calculations involving a term K which I want in the final answer

import numpy as np
theta =np.arange(0, 362, 2)
dist=np.zeros(181)
for i in range(181):
   if(theta[i]<90):
      dist[i]= ((np.sin(45)*K)/(np.sin(135-theta[i])))
   elif(theta[i]>90 and theta[i]<180):
      dist[i]= ((np.sin(45)*K)/(np.sin(theta[i]-45)))
   elif(theta[i]>180 and theta[i]<270):
      dist[i]= ((np.sin(45)*K)/(np.sin(theta[i]-135)))
   elif(theta[i]>270 and theta[i]<360):
      dist[i]= ((np.sin(45)*K)/(np.sin(theta[i]-225)))
   else:
      dist[i]=K

print(dist)

Is there any way for the answer to be stored in the format - 0.79K 0.34K and so on...

Also is there any more efficient way to do what I've done in the above code ? (take a list of thetha values from 0-360 and find and store the respective dist values as per the same conditions I've used above)

0 Answers
Related