samedi 4 novembre 2017

Python IF condition is not satisfy but it enter the script. Numpy any() and all() issue

I have this condition for staring an if, and I think it is starting when not expected, maybe one of you could point me my error or advice a better approach

This is the part of the script:

I obtain values for some angles and assign them to T2, then at some point I compare

...
if 0 <= np.any(T2[i:]) < 0.5*np.pi:
 Do something

The values in that array do not satisfy the condition, but it enter in the conditional anyway and I do not know why

Checking in the console I get:

In [10]: T2
Out[10]: array([ 1.84103563,  2.68108542,  2.73258615,  2.7358088 ,  2.76608758,
    2.8106091 ])
In [10]: 0 <= np.any(T2) < 0.5*np.pi
Out[10]: True

Another evaluation output:

In [15]: np.degrees(T2) < 10
Out[15]: array([False, False, False, False, False, False], dtype=bool)

In [16]: np.any(np.degrees(T2)) < 10
Out[16]: True

So I guess it is a problem with the use of .any/.all

Before posting I finally check:

In [27]: np.degrees(np.all(T2[i:]))
Out[27]: 57.281

Where came the value that is being assigned to the array? How do you avoid that? Is any other way to do conditionals with arrays?

Aucun commentaire:

Enregistrer un commentaire