-2

I want to compare item in list, this is my code:

for i in range(200):
        if g[i]==1 and d[4]==1:
           TP += 1
        elif g[i]==1 and d[4]==0:
           FP += 1
        elif g[i]==0 and d[4]==1:
           FN += 1
        elif g[i]==0 and d[4]==0:
           TN += 1

and I got this Error :

the truth value of an array with more than one element is ambiguous. use a.any() or a.all()

I don't know how to use the syntax as recommended above, how to solve it, thanks.

mfathirirhas
  • 2,169
  • 5
  • 23
  • 35

1 Answers1

3

As mentioned by the author in comments, d is a 2-dimensional Numpy array.

The answer to that question explains that comparing multidimensional arrays in Numpy requires to the kind of comparison you want to perform (either any element is bitwise true or all elements are bitwise true).
That is the reason why you have to specify which kind of comparison you want, with (g[i] - d[4]).any() or (g[i] - d[4]).all().

Community
  • 1
  • 1
filaton
  • 2,257
  • 17
  • 27