You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多
文档控制台
免费开始使用

numpy.atan与numpy.arctan是否存在差异?实测未发现区别

NumPy中np.atan与np.arctan的区别?

在NumPy里,np.atannp.arctan完全没有差异,它们是同一个函数的不同别名;同理,np.atan2np.arctan2也是完全等价的。

出现两组命名的原因是为了兼容不同的使用习惯:

  • atan是偏向编程领域的命名(比如C语言标准库就采用该命名)
  • arctan是数学领域的标准函数名称

两者底层指向同一实现,所以传入相同参数时,必然得到完全一致的结果——这也是你的测试代码看不出区别的核心原因。

你的测试代码如下:

import numpy as np
for i in np.arange(0,2*np.pi,.1):
    x = np.cos(i)
    y = np.sin(i)
    th = np.atan(y/x)
    th2 = np.atan2(y,x)
    th3 = np.arctan(y/x)
    th4 = np.arctan2(y,x)
    print(f'atan {th} atan2 {th2} arctan {th3} arctan2 {th4}')

内容的提问来源于stack exchange,提问作者jeremy_rutman

火山引擎 最新活动