值错误,错误真理,不明确的错误 [英] Value error, truth error, ambiguous error

查看:166
本文介绍了值错误,错误真理,不明确的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用本code

 for i in range(len(data)):
   if Ycoord >= Y_west and Xcoord == X_west:
        flag = 4

我得到这个ValueError错误

I get this ValueError

如果YCOORD> = Y_west和XCOORD == X_west:
ValueError错误:与多个元件的阵列的真值是不明确的。使用a.any()或a.all()

if Ycoord >= Y_west and Xcoord == X_west: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

然后我使用上述限制

我如何能保持我的限制,我的文件的写下去?任何帮助

Any help on how i can keep my restriction and go on with the writing of my file?

推荐答案

变量 YCOORD XCOORD 可能 numpy.ndarray 的对象。你必须使用数组兼容运营商检查其所有值的状态。您可以创建一个标志数组,并设置在所有地方的值 4 您的条件是

The variables Ycoord and Xcoord are probably numpy.ndarray objects. You have to use the array compatible and operator to check all its values for your condition. You can create a flag array and set the values to 4 in all places where your conditional is True:

check = np.logical_and(Ycoord >= Y_west, Xcoord == X_west)
flag = np.zeros_like(Ycoord)
flag[check] = 4

或你有你的code做的测试值按值:

or you have to test value-by-value in your code doing:

for i in range(len(data)):
    if Ycoord[i] >= Y_west and Xcoord[i] == X_west:
        flag = 4

这篇关于值错误,错误真理,不明确的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆