Nick Agiazis
Nick Agiazis

Reputation: 11

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

I was trying to figure out why this error keeps happening with my specific code as i'm trying to get better with numpy and mathematics within python. I keep getting this as a error and i can't seem to figure out a fix to it.enter image description here

Upvotes: 1

Views: 153

Answers (1)

Frank Yellin
Frank Yellin

Reputation: 11240

You should not write if a == b: to compare two numpy arrays. The value of a == b is a boolean array comparing the corresponding elements of a and b. The error message is telling you that you should be writing np.all(a == b).

Numpy gives you this error message any time it sees the user trying to take the boolean value of an array.

Upvotes: 1

Related Questions