error using all()/numpy [TypeError: cannot perform reduce with flexible type]
Peter Otten
__peter__ at web.de
Fri May 23 04:07:08 EDT 2008
Marc Oldenhof wrote:
> I'm pretty new to Python, but use it a lot lately. I'm getting a crazy
> error trying to do operations on a string list after importing numpy.
> Minimal example:
>
> [start Python]
>
> Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
> (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>
>>>> a=['1','2','3']
>>>> all(a)
> True
>>>> from numpy import *
>>>> all(a)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "C:\Python25\lib\site-packages\numpy\core\fromnumeric.py", line
> 982, in all
> return _wrapit(a, 'all', axis, out)
> File "C:\Python25\lib\site-packages\numpy\core\fromnumeric.py", line
> 37, in _wrapit
> result = getattr(asarray(obj),method)(*args, **kwds)
> TypeError: cannot perform reduce with flexible type
>
> [end of example]
>
> It seems that Python calls numpy's "all" instead of the standard one,
> is that right? If so, how can I call the standard "all" after the
> numpy import? ["import numpy" is not a desirable option, I use a lot
> of math in my progs]
>
> Is there another way around this error?
That's not an error; star-import is a rebinding operation, just like
assignments and the def statement.
>>> from numpy import *
>>> del all, sum, any
>>> all("123")
True
Peter
More information about the Python-list
mailing list