|  | 
 
| 
使用Numpy功能求正余弦的值
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  要求:使用Numpy功能,尽量避免使用for或者while循环
 
 正确的输出应如下所示:
 sin(000 deg) = 0.000 & cos(000 deg) = 1.000
 sin(015 deg) = 0.259 & cos(015 deg) = 0.966
 sin(030 deg) = 0.500 & cos(030 deg) = 0.866
 sin(045 deg) = 0.707 & cos(045 deg) = 0.707
 sin(060 deg) = 0.866 & cos(060 deg) = 0.500
 sin(075 deg) = 0.966 & cos(075 deg) = 0.259
 sin(090 deg) = 1.000 & cos(090 deg) = 0.000
 sin(105 deg) = 0.966 & cos(105 deg) =-0.259
 ...skip...
 sin(315 deg) =-0.707 & cos(315 deg) = 0.707
 sin(330 deg) =-0.500 & cos(330 deg) = 0.866
 sin(345 deg) =-0.259 & cos(345 deg) = 0.966
 sin(360 deg) =-0.000 & cos(360 deg) = 1.000
 
复制代码import numpy as np
x = np.arange(0,360,15).reshape(24,1)
x = np.char.asarray(x.astype(np.str_)).rjust(3,'0')
y1 = np.arange(0,360,15).reshape(24,1)
y2 = y1 + 90
y1 = np.around(np.sin(y1*np.pi/180),decimals=3)
y1_ = y1.copy()
y1 = np.char.asarray(y1.astype(np.str_))
y1 = (y1 * (1*(y1_>=0))).ljust(5,'0').replace('00000','') + (y1 * (1*(y1_<0))).ljust(6,'0').replace('000000','')
y2 = np.around(np.sin(y2*np.pi/180),decimals=3)
y2_ = y2.copy()
y2 = np.char.asarray(y2.astype(np.str_))
y2 = (y2 * (1*(y2_>=0))).ljust(5,'0').replace('00000','') + (y2 * (1*(y2_<0))).ljust(6,'0').replace('000000','')
r = 'sin('+x+' deg) = '+y1+' & cos('+x+' deg) = '+y2
print(str(r).replace("'",'').replace("[",'').replace("]",''))
写这个累死我了  | 
 |