mypy失败了numpy总和

发布于 2025-01-24 22:15:23 字数 500 浏览 1 评论 0原文

此代码片段有效:

py -c "import numpy; print(numpy.array([[1,2,3],[4,5,6]]).sum(axis=0) % 2)"
[1 1 1]

但是Mypy出现了一个错误:

py -m mypy -c "import numpy; print(numpy.array([[1,2,3],[4,5,6]]).sum(axis=0) % 2)"
<string>:1: error: Unsupported operand types for % ("number[Any]" and "int")
<string>:1: note: Left operand is of type "Union[number[Any], ndarray]"
Found 1 error in 1 file (checked 1 source file)

这是我的代码段中的mypy错误还是numpy错误或错误?

This code snippet works:

py -c "import numpy; print(numpy.array([[1,2,3],[4,5,6]]).sum(axis=0) % 2)"
[1 1 1]

But mypy gives an error:

py -m mypy -c "import numpy; print(numpy.array([[1,2,3],[4,5,6]]).sum(axis=0) % 2)"
<string>:1: error: Unsupported operand types for % ("number[Any]" and "int")
<string>:1: note: Left operand is of type "Union[number[Any], ndarray]"
Found 1 error in 1 file (checked 1 source file)

Is this a mypy bug or a numpy bug or a bug in my code snippet?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

是你 2025-01-31 22:15:23

这是一个麻烦的错误,直到numpy 1.20.3 https://github.com/numpy/numpy/numpy/问题/18305

This was a numpy bug until numpy 1.20.3 https://github.com/numpy/numpy/issues/18305

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文