I'm adaptying the code of a guy that studies with me, for my problem.

This is his code:

 if not((paux1 == paux2).all()): pop[int(saidaFO[pos,0]),:] = paux2 pos -= 1 

And it works, and when I give a print, I have this result by paux1: [-2.3668 1.3174]. I'm working in a different problem, and in my case, when I print paux1, I have this: [0.2107491848569726, 443, 3]

So, when I try to do the same comparation:

if not((paux1 == paux2).all()):

I got this error: "AttributeError: 'bool' object has no attribute 'all' " I'm not understand what is going on... Could someone help me, please? I didn't understand so well how the .all() works... Maybe a equivalent code can work...

4

2 Answers

In your guy's code, paux1 and paux2 are probably numpy arrays, so paux1 == paux2 returns an array representing booleans (whether the tested equality is true or false), and that array does have a .all() method.

It sounds like you are working with lists, so paux1 == paux2 does not compare elements by elements like numpy arrays do. You are only checking if both lists are equal, with returns a single boolean. This boolean does not have a .all() method and that's what causes your error.

Convert your lists of values beforehand to numpy arrays and the error should be fixed.

paux1 = np.array(paux1) paux2 = np.array(paux2) 
4

Another source of error is if the two np.array don't have the same shape. For instance:

(np.array([[1,1]])==np.array([1,2,3])).all() 

returns:

 --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-400-ea9825114062> in <module> ----> 1 (np.array([[1,1]])==np.array([1,2,3])).all() AttributeError: 'bool' object has no attribute 'all' 
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy