【发布时间】:2019-05-15 02:24:07
【问题描述】:
我收到以下代码的值错误:
def ReLu(x):
if x>0:
return x
else:
return 0
当我使用矩阵调用函数时发生错误
x = np.random.randn(4,4)
z = ReLu(x)
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
【问题讨论】:
-
你不能用矩阵来调用它。错误消息告诉你原因。
-
你的函数需要一个单一的值,但是你给它传递了一个向量。如果你想让它作为一个向量函数工作,你必须使用向量化操作来编写。
-
Jaswanth,函数
ReLu应该做什么?如果您希望我们为您提供帮助,请澄清这一点
标签: python python-3.x deep-learning