subtle error slows code by 10x (builtin sum()) - replace builtin sum without using import?

2011-07-01 Thread bdb112
First a trap for new players, then a question to developers Code accelerated by numpy can be slowed down by a large factor is you neglect to import numpy.sum . from timeit import Timer frag = 'x=sum(linspace(0,1,1000))' Timer(frag ,setup='from numpy import linspace').timeit(1000) # 0.6 sec Timer(

Re: breaking out to the debugger (other than x=1/0 !)

2009-10-23 Thread bdb112
The example here is for pydb which works as well (and is more like gdb). On Oct 23, 12:07 pm, "Diez B. Roggisch" wrote: > bdb112 wrote: > > After a while programming in python, I still don't know how to break > > out to the debugger other than inserting an instruction t

breaking out to the debugger (other than x=1/0 !)

2009-10-23 Thread bdb112
After a while programming in python, I still don't know how to break out to the debugger other than inserting an instruction to cause an exception. x=1/0 In IDL one woudl write stop,'reason for stopping...' at which point you can inspect locals (as in pdb) and continue (but you can't with pdb if

breaking out to the debugger (other than x=1/0 !)

2009-10-23 Thread bdb112
After a while programming in python, I still don't know how to break out to the debugger other than inserting an instruction to cause an exception. x=1/0 In IDL one woudl write stop,'reason for stopping...' at which point you can inspect locals (as in pdb) and continue (but you can't with pdb if

pylab/matplotlib large plot memory management - bug? or tuning parameter needed?

2009-10-19 Thread bdb112
Summary: It is not straightforward to avoid memory leaks/consumption in pylab. If we define x = arange(1e6) # adjust size to make the increment visible, yet fast enough to plot # then repetition of plot(x,hold=0) # consumes increasing memory according to ubuntu system monitor Details: #vers

Re: clean way prepend an element to a numpy array

2009-07-20 Thread bdb112
On Jul 21, 2:13 pm, Ben Finney wrote: > bdb112 writes: > > If I want to add an element at the beginning of an array, it seems > > like I must make a list, insert in place, then make an array again. > > The NumPy ‘ndarray’ type (which is what you get by default from the >

clean way prepend an element to a numpy array

2009-07-20 Thread bdb112
If I want to add an element at the beginning of an array, it seems like I must make a list, insert in place, then make an array again. Of course, lists can be efficient too, and the insert() funtion works nicely in that case, but sometimes arrays are the best choice e.g. x=array([1,2,3]) # to put

Re: and [True,True] --> [True, True]?????

2009-04-20 Thread bdb112
THanks Gabriel, Now I know about the zip function. Your explanation of Boolean ops on lists was clear. It leads to some intriguing results: bool([False]) --> True I wonder if python 3 changes any of this? > A and B means: check the boolean value of A; if it's false, return A.   > Else, return B

[False,True] and [True,True] --> [True, True]?????

2009-04-20 Thread bdb112
Is there any obvious reason why [False,True] and [True,True] gives [True, True] Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] -- http://mail.python.org/mailman/listinfo/python-list

Re: print - bug or feature - concatenated format strings in a print statement

2009-03-17 Thread bdb112
one. (+). On Mar 16, 5:00 pm, bdb112 wrote: > #   is the difference between > print(" %d,  %d, buckle my shoe" % (1,2)) > #   and > print(" %d, " + " %d, buckle my shoe" % (1,2)) > # a bug or a feature? > > First output > ... print(" %d &quo

Re: print - bug or feature - concatenated format strings in a print statement

2009-03-16 Thread bdb112
#whoops, the first output is actually 1, 2, buckle my shoe # in case it wasn't obvious On Mar 16, 5:00 pm, bdb112 wrote: > #   is the difference between > print(" %d,  %d, buckle my shoe" % (1,2)) > #   and > print(" %d, " + " %d, buckle my shoe&q

print - bug or feature - concatenated format strings in a print statement

2009-03-16 Thread bdb112
# is the difference between print(" %d, %d, buckle my shoe" % (1,2)) # and print(" %d, " + " %d, buckle my shoe" % (1,2)) # a bug or a feature? First output ... print(" %d " + " %d, buckle my shoe" % (1,2)) Second output TypeError: not all arguments converted during string formatting Versio

Re: ipython / vs \ in readline on MS Windows (and ipython help grepper)

2009-03-10 Thread bdb112
thon25/python.exe "C:\Python25\scripts\ipython" -pylab $* (Same problem if I use the windows Start menu Ipython IPython and pysh) On Mar 11, 7:34 am, bdb112 wrote: > Q1/ I run a standard python ditribution with ipython and readline > under cygwin.  The tab filename completion w

ipython / vs \ in readline on MS Windows (and ipython help grepper)

2009-03-10 Thread bdb112
Q1/ I run a standard python ditribution with ipython and readline under cygwin. The tab filename completion works fine in the OS (bash shell) as expected, and tab filename completion at the ipython command line works, but with MS style path separators (backslash: run examples \test.py) which the r

Re: docstring reference to another docstring

2009-03-09 Thread bdb112
t("ClusterSet.plot body") plot.__doc__ += "extra" + Cluster.plot.__doc__ cs=ClusterSet() print(cs.__doc__) print(cs.plot.__doc__) On Mar 10, 7:30 am, Chris Rebert wrote: > On Mon, Mar 9, 2009 at 3:23 PM, bdb112 wrote: > > A function of the class ClusterSet uses

docstring reference to another docstring

2009-03-09 Thread bdb112
A function of the class ClusterSet uses a similar function of the class Cluster to do most of its work. Its docstring could have so much in common with that in Cluster that it could be just a line or two in addition to that of Cluster. Is there a way for the ClusterSet docstring to tack the Clust