Question
Why does
any(['','foo'])
raise the exception
TypeError: cannot perform reduce with flexible type
I thought it should evaluate to True
, because
bool('')
evaluates toFalse
bool('foo')
evaluates toTrue
- I though
any()
could be used with any sequence of objects that are convertible tobool
I'm using Python 2.7.
Solution
You are accidentally calling numpy.any()
instead of the built-in any()
. The latter does work for your example.
To fix this, you need to sort out the imports. Look for from numpy import *
and from numpy import any
, and for similar imports involving scipy
and pylab
.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow