-3

For some backstory I am writing a program that involves a grid of squares that can all be of various colors, I decided that I would store the colors in a NumPy array (i have basically no experience with NumPy). I formated the array so that it was a 2d array and each position in it correlated to the position of the grid space. I need to check the current color so I did what I would do if it was just a list (for context array is the name of the array):

color = 0, 0, 0
array = numpy.array([(color,color,color,color),
                     (color,color,color,color),
                     (color,color,color,color)])
if array[0,0] == color:
    #other code that doesn't matter

The if statement is where the error occurs and I can't find anything about what to do when this error comes up in an if statement only with and/or. If anybody has some insight into this problem any help would be greatly appreciated

  • 4
    This error is not from the code you posted. Probably from code inside the `if` that you didn't posted (other code that *does* matter). – Guy Aug 04 '21 at 07:43
  • I doubt that because I have tested the code inside the it statement outside of it and it works, plus the error is thrown at the line that literally says if. – ItsTrashPanda Aug 04 '21 at 23:20

1 Answers1

-1

Explanation is provided over here: https://stackoverflow.com/a/65082868/7225290

No error will be thrown if you are comparing value at particular index with the value(having same datatype).

It occurs when you try to do

array = numpy.array([(0,0,0,0),
                     (0,0,0,0),
                     (0,0,0,0)])

if array:#Comparing object of type numpy.ndarray with boolean causes the error
   pass

  • Instead of posting an answer edit your question and include the code that throws the error, `over here you will see an error` doesn't mean anything. – Guy Aug 04 '21 at 07:56
  • That’s why I was so confused, it seemed like everything should have worked. I don’t know if this makes a difference but I’m my actual code I am storing tuples in the array and I am comparing them to tuples so I don’t see why that wouldn’t work, I see now that I should have made the code I shared closer to what it actually is so I edited my initial post. – ItsTrashPanda Aug 04 '21 at 23:28