Numpy boolean logic (check if element is not something)

Viewed 96

when I run if field[x,y,z] != [-1,-1,-1]: this error is displayed:

Traceback (most recent call last):
  File "C:\Users\dinos\Desktop\CODE\Render\Camera.py", line 63, in controll
    print(self.snap())
  File "C:\Users\dinos\Desktop\CODE\Render\Camera.py", line 59, in snap
    return "".join(self.breakUpArray(self.pBetweenPlane(),self.ep["ab"]))+"\n"+self.getInfo()
  File "C:\Users\dinos\Desktop\CODE\Render\Camera.py", line 42, in pBetweenPlane
    if self.field.field[p2[0],p2[1],p2[2]] != self.field.background:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

"field" is a 4d-np array created with np.full([100, 100, 100, 3], -1). I know the errormessage does give a hint but how would I check if field[x,y,z] is not [-1,-1,-1]?

1 Answers

np.array([-1, -1, -1]) == [-1, -1, -1] evaluates to [True, True, True] as numpy compares them index by index

you'd probably want if not all(field[x,y,z] == [-1,-1,-1])

Related