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 to False
  • bool('foo') evaluates to True
  • I though any() could be used with any sequence of objects that are convertible to bool

I'm using Python 2.7.

Was it helpful?

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
scroll top