重现代码:
import numpy as np
y1, y2 = [5, 3]
print(np.arctan2(y1, y2)) # Output: 1.0303768265243125
print(np.arctan2(x1=y1, x2=y2))
# Output:
#---------------------------------------------------------------------------
#ValueError Traceback (most recent call last)
#<ipython-input-13-b7d0f788df1f> in <module>()
#----> 1 np.arctan2(x1=y1, x2=y2)
#ValueError: invalid number of arguments
我无法解释抛出的 ValueError。我希望两者在语义上是相同的。这是 Python、Numpy 的问题还是我缺乏理解?
这是 arctan2 的定义在 Numpy 中:
def arctan2(x1, x2, *args, **kwargs)
我使用的版本:
- Linux-4.13.0-38-generic-x86_64-with-debian-stretch-sid
- Python 3.6.1(默认,2017 年 6 月 16 日,16:00:03)[GCC 5.4.0 20160609]
- NumPy 1.14.2
最佳答案
参数x1
和x2
被称为positional-only parameters .这在 arctan2
文档中由函数签名中的 /
字符指示:
numpy.arctan2(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'arctan2'
^
关于python - numpy arctan2 参数根据语法导致 ValueError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49690325/