Skip to content Skip to sidebar Skip to footer

Value Error, Truth Error, Ambiguous Error

When using this code for i in range(len(data)): if Ycoord >= Y_west and Xcoord == X_west: flag = 4 I get this ValueError if Ycoord >= Y_west and Xcoord == X_west

Solution 1:

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

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

Post a Comment for "Value Error, Truth Error, Ambiguous Error"