![](/img/trans.png)
[英]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.