gpt4 book ai didi

python:numpy.where 出错

转载 作者:太空宇宙 更新时间:2023-11-03 14:22:06 25 4
gpt4 key购买 nike

我正在尝试使用 numpy.where 函数,如下所示:

x= np.where(segments==1000 and segments == 0)

然后我得到一个 ValueError:

ValueError: The truth value of an array with more than one element is ambiguous. 
Use a.any() or a.all()

浏览其他一些线程,这似乎是预期的行为。但是,我不确定如何使用 numpy.any() 重新表述它。我无法获得正确的语法。

最佳答案

您可以使用括号和 &np.logical_and 而不是 and 来构建您的条件:

(segments == 1000) & (segments == 0)

或:

np.logical_and(segments == 1000, segments == 0)

关于python:numpy.where 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26405751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com