python - numpy arctan2 参数根据语法导致 ValueError

标签 python numpy

重现代码:

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

最佳答案

参数x1x2 被称为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/

相关文章:

python - 图像不是从 Amazon S3 存储桶加载的

python - OpenAI API错误: "The model ' curie:ft-personal-2023-09-15-06-05-0 1' does not exist" when trying to delete a fine-tuned model

python - 随机交换两列 pandas dataframe 的元素

Python通过特定方程列出交叉识别(重叠?)

python - 从嵌套列表创建数组时抑制 Numpy 中的科学记数法

python - 使用 FastCGI 将 Windows 身份验证上下文从 IIS 传递到 Python

python - 从远程机器上的 docker 容器上执行命令

虚奇函数的 Python 傅里叶逆变换

python - 类型错误 : Mismatch between array dtype ('float64' ) and format specifier

python - 具有意外结果的正弦波的傅里叶变换