gpt4 book ai didi

python - 带有 ndarray 或矩阵操作数的 @ 运算符出现新的意外操作数错误

转载 作者:太空宇宙 更新时间:2023-11-04 02:34:14 24 4
gpt4 key购买 nike

我以前可以使用@ 进行矩阵乘法,但由于某些原因,它不再起作用了。我正在运行 Python 3.5.4,在 IPython 6.2.1 或笔记本 5.0.0 中,出现了这个意外错误:

In [1]: from numpy import arange

In [2]: A = arange(5)

In [3]: B = arange(15).reshape((5,3))

In [4]: A @ B
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-455d622f3b50> in <module>()
----> 1 A @ B

TypeError: unsupported operand type(s) for @: 'numpy.ndarray' and 'numpy.ndarray'

使用 matrix 类型没有帮助:

In [5]: from numpy import matrix

In [6]: A = matrix(arange(5))

In [7]: B = matrix(arange(15).reshape((5,3)))

In [8]: A @ B
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-8-455d622f3b50> in <module>()
----> 1 A @ B

TypeError: unsupported operand type(s) for @: 'matrix' and 'matrix'

我在这里完全不知所措。 @ 运算符是否已弃用?我错过了一些明显的东西吗?这是我在修改大约一年前运行良好的笔记本时出现的。是否有一些其他信息可以帮助诊断正在发生的事情?

最佳答案

据我所知,事实证明,根据 cxw 的评论,使用正确版本的 numpy 是一个问题。我已经更新了 numpy,现在似乎一切正常。

关于python - 带有 ndarray 或矩阵操作数的 @ 运算符出现新的意外操作数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48327085/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com