2

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]?

  • 2
    One way is to check the sum of the array. If it’s not -3000000 (for example) then one or more values is not -1. Or check the sum of each axis ... same logic applies. –  Nov 19 '20 at 22:49

1 Answers1

2

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])

0xDECAFC0FFEE
  • 370
  • 1
  • 5