numpy arctan2 错误或使用问题? [英] numpy arctan2 bug or usage issues?

查看:123
本文介绍了numpy arctan2 错误或使用问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 Excel 电子表格中的一些函数翻译成 python.我需要使用 atan2根据 numpy 文档,这是 arctan2:arctan2.问题是这两个结果甚至不接近:

I'm translating some functions from an Excel spreadsheet into python. I need to use atan2 which is arctan2 according to numpy docs: arctan2. The problem is that the two results are not even close:

oc = 23.4384863405
sal = 89.7814630647
sra = np.arctan2(np.cos(np.deg2rad(sal)),
         np.cos(np.deg2rad(oc))*np.sin(np.deg2rad(sal)))
results: Excel = 1.566714757 Numpy = 0.00415720646  ??

我相信 Excel 结果是正确的.这是错误的.

I trust the Excel results as it is correct. It is numpy that is wrong.

现在要么我没有正确使用 arctan2,要么 atan2 不是 numpy 中的 arctan2,要么 numpy 中存在错误,或者我完全迷失在这里.

Now either I'm not using arctan2 correctly, or atan2 is not arctan2 in numpy, or there is a bug in numpy, or I'm just completely lost here.

我使用的是 python 版本 2.7.2 和 numpy 1.6.2

I'm using python version 2.7.2 and numpy 1.6.2

有什么想法吗?谢谢

推荐答案

来自 Excel文档:

ATAN2 函数的语法是:

The syntax for the ATAN2 function is:

ATAN2(x 坐标,y 坐标)

ATAN2( x-coordinate, y-coordinate )

来自 numpy 文档:

numpy.arctan2(x1, x2[, out])

numpy.arctan2(x1, x2[, out])

x1/x2 的元素方向反正切正确选择象限.

Element-wise arc tangent of x1/x2 choosing the quadrant correctly.

选择象限(即分支)使得 arctan2(x1, x2) 是终止于原点的射线与以弧度为单位的带符号角通过点 (1,0),射线终止于原点和通过点 (x2, x1).(注意角色转换:y 坐标"是第一个函数参数,x 坐标"是第二个.)

The quadrant (i.e., branch) is chosen so that arctan2(x1, x2) is the signed angle in radians between the ray ending at the origin and passing through the point (1,0), and the ray ending at the origin and passing through the point (x2, x1). (Note the role reversal: the "y-coordinate" is the first function parameter, the "x-coordinate" is the second.)

他们以相反的顺序进行论证.因此:

They take their arguments in opposite order. Thus:

In [31]: arctan2(cos(deg2rad(sal)), cos(deg2rad(oc))*sin(deg2rad(sal)))
Out[31]: 0.0041572064598812417

In [32]: arctan2(cos(deg2rad(oc))*sin(deg2rad(sal)), cos(deg2rad(sal)))
Out[32]: 1.5666391203350154

这篇关于numpy arctan2 错误或使用问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆