Hello all,
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?
Marc 5 6753
On 23 mei, 09:12, Marc Oldenhof <foul_ole_r...@yahoo.comwrote:
Hello all,
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?
Marc
Never mind, I found a way. For reference:
>>import __builtin__ __builtin__.all(a)
True
Works!
Marc
Marc Oldenhof wrote:
Hello all,
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?
Yes, there are several solutions, but before that I'll say that "from
.... import *" is frowned upon for just this reason. You have no
control (and often no idea) what * ends up importing, and if any of
those names overwrite an existing name (as you've found here), you may
not notice. (It's not quite fair to say "Python calls numpy's "all".
*You* call it after you chose to replace Python's "all" with numpy's "all".)
Solutions:
Save Python's "all" first under another name:
original_all = all
from numpy import all
Now you can call all(...) or original_all(...).
The built-in (as they are called) are always available through __builtins__:
from numpy import *
all(...) # is numpy's all
__builtins__.all(...) # Is the original all
Don't import *, but rather import only those things you need.
from numpy import array, dot, float32, int32, ...
and if you need numpy's all
from numpy import all as numpy_all
Gary Herron
Marc
-- http://mail.python.org/mailman/listinfo/python-list
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
On Fri, 23 May 2008 00:12:35 -0700, Marc Oldenhof wrote:
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]
I think the ideal solution is to try and persuade yourself that typing
"numpy." in front of some functions now and then is not that big a price
to pay to avoid name collisions; using an editor with code completion
would probably help in that task.
You could also try:
import numpy as n
which reduces the typing a bit and limits you to one possible name
collision, or
from numpy import array, gradient #and whatever else you need
or
import numpy
array = numpy.array
gradient = numpy.gradient # Then you can access the names you use a lot
# directly, while accessing stuff you use less
# frequently via numpy.whatever
in which case you'll know exactly which names you're overwriting. Peter's
solution, of explicitly deleting some names that you've imported, strikes
me as less good, because you might find the same problem recurs later, if
the numpy developers add new names to the module.
On 23 mei, 09:12, Marc Oldenhof <foul_ole_r...@yahoo.comwrote:
<snip my post>
Thanks for the reactions, I'll use the "from numpy import <individual
stuff>" from now on :)
Marc This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Thomas Philips |
last post by:
To compute the product of a list of numbers, I tried entering
>>>reduce(__mul__,)
Traceback (most recent call last):
File "<pyshell#0>", line 1, in -toplevel-
reduce(__mul__,)
NameError: name...
|
by: Jon Guyer |
last post by:
>>> This is a fake line to confuse the stupid top-posting filter at gmane
We have a rather complicated class that, under certain circumstances, knows
that it cannot perform various arithmetic...
|
by: Boris Borcic |
last post by:
after a while trying to find the legal manner to file numpy bug reports,
since it's a simple one, I thought maybe a first step is to describe the bug
here. Then maybe someone will direct me to the...
|
by: Iljya |
last post by:
Hello,
I need to pickle the type numpy.float32 but encounter an error when I
try to do so. I am able to pickle the array itself, it is specifically
the type that I cannot pickle.
I am using:...
|
by: mcdurr |
last post by:
I recently installed Python 2.5 on Windows and also installed numpy
1.0. I'd like to compute an FFT on an array of numbers but I can't
seem to access the FFT function. I'm fairly new to Python...
|
by: robert |
last post by:
Is there a ready made function in numpy/scipy to compute the correlation y=mx+o of an X and Y fast:
m, m-err, o, o-err, r-coef,r-coef-err ?
Or a formula to to compute the 3 error ranges?
...
|
by: John [H2O] |
last post by:
There's a lot of greek for me here ... should I post to numpy-discussions as
well???
The backtrace is at the bottom.... Thanks!
GNU gdb Fedora (6.8-21.fc9)
Copyright (C) 2008 Free...
|
by: Slaunger |
last post by:
I know there must be a simple method to do this.
I have implemented this function for calculating a checksum based on a
ones complement addition:
def complement_ones_checksum(ints):
"""...
|
by: Slaunger |
last post by:
Hi,
This is my first post here, I am looking forward to being here.
I have actually posted almost the same question on comp.lang.python:
...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...
|
by: MeoLessi9 |
last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: marcoviolo |
last post by:
Dear all,
I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
| |