【发布时间】:2019-12-07 16:50:15
【问题描述】:
具有多个元素的数组的真值是不明确的。使用 a.any() 或 a.all()
我收到此代码的上述错误。几个月前我没有收到这种错误。但我现在明白了。我该如何解决这个问题?
t = np.linspace(np.zeros((2, 2)), np.ones((2, 2)), 20)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-19-187bbe847597> in <module>
----> 1 t = np.linspace(np.zeros((2, 2)), np.ones((2, 2)), 20)
~\Anaconda3\lib\site-packages\numpy\core\function_base.py in linspace(start, stop, num, endpoint, retstep, dtype)
122 if num > 1:
123 step = delta / div
--> 124 if step == 0:
125 # Special handling for denormal numbers, gh-5437
126 y /= div
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
【问题讨论】:
-
你能显示完整的错误跟踪吗?
-
您使用的是哪个版本的
numpy?试试np.version.version。 -
当我在我的机器(python 3.7.3 和 numpy 1.16.4)上执行您的代码示例时,我没有收到任何错误。你用的是哪个版本的 python 和 numpy?
-
我可以在
numpy1.16 之前的版本中复制此错误。此后,错误跟踪中的该代码将不存在。在此之前,不支持对linspace的输入。 -
我正在使用'1.14.5'