[英]The truth value of an array with more than one element is ambiguous Python error
[英]"The truth value of an array with more than one element is ambiguous" error [Python]
index = np.where(slopes > mean - 2 * sd and slopes < mean + 2 * sd)[0]
返回此错误:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
如果我改为写idx = np.where(slopes < mean + 2 * sd)[0]
或idx = np.where(slopes > mean - 2 * sd)[0]
我得到正确的索引。 为什么我不能结合这两个条件?
而不是使用boolean 'and' :
index = np.where((slopes > mean - 2 * sd) and (slopes < mean + 2 * sd))[0]
使用按位 '&'尝试您的代码:
index = np.where((slopes > mean - 2 * sd) & (slopes < mean + 2 * sd))[0]
注意:有关boolean 'and'和按位 '&' 的更多信息,您可以参考此问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.