簡體   English   中英

“具有多個元素的數組的真值不明確”錯誤 [Python]

[英]"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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM