mardi 10 septembre 2019

ValueError in For Loop's If Condition with two boolean arrays

I'm running a For-Loop with an If Statement including two boolean Arrays to create a new array.

I already tried all Solutions I could find on StackOverflow, exchanging the & with Logical_and or bitwise_and, also using the suggested a.any() & a.all() methods, I still get the same ValueError.

y_valid = [True, False, True, False, False, True]
y_pred = [False, False, True, True, False, False]

for i in (y_valid, y_pred):
    CM = []
    if (y_valid[i] == False) & (y_pred[i] == False):
        CM == 0
    elif (y_valid[i] == False) & (y_pred[i] == True):
        CM == 1
    elif (y_valid[i] == True) & (y_pred[i] == False):
        CM == 2
    elif (y_valid[i] == True) & (y_pred[i] == True):
        CM == 3

I expect to get an array CM including numerals from 0-3

My Output:

ValueError                                Traceback (most recent call last)
<ipython-input-107-259ac7895185> in <module>
      1 for i in (y_valid, y_pred):
      2     CM = []
----> 3     if (y_valid[i] == False) & (y_pred[i] == False):
      4         CM == 0
      5     elif (y_valid[i] == False) & (y_pred[i] == True):

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

Aucun commentaire:

Enregistrer un commentaire