-1

Basically i am trying out boolean expressions with numpy arrays , for example something like this:

import numpy as np
a = np.array([1,0,1])
b = np.array([0,1,1])
c = np.array([1,0,1])

if (a ==b) or (a==c):
    d = [2,5,5]
else : d = [1,5,5]
print d

This returns an error

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

What would be the correct way to code this?

1 Answers1

0

the condition should read:

if (a==b).all() or (a==c).all():

see this question

Community
  • 1
  • 1
ewcz
  • 12,819
  • 1
  • 25
  • 47