Re: [Tutor] Refining Code

2014-04-11 Thread bob gailer
On 4/10/2014 6:26 PM, Saba Usmani wrote: My task is : Welcome to the tutor list. In what school are you learning Python? What version of Python? What operating system? What do you use to write and run your code? What Python elements have you studied so far? Your code can be greatly simpli

Re: [Tutor] Creating an Invalid message for user

2014-04-11 Thread Dave Angel
Saba Usmani Wrote in message: > > You posted in html so I can't quote your code, but why aren't you using int() to convert in one call? Second argument is the base to be used. value = int ("10011", 2) othervalue = int ("234") # default to decimal -- DaveA _

Re: [Tutor] Creating an Invalid message for user

2014-04-11 Thread Mark Lawrence
On 11/04/2014 21:58, Saba Usmani wrote: Hi, I am meant to design code for a program that converts from binary number to decimal and vice versa. This is what i have so far: print "Welcome to the binary and decimal converter" loop = True while loop: bord = raw_input("Enter b for binary or d

[Tutor] Creating an Invalid message for user

2014-04-11 Thread Saba Usmani
Hi, I am meant to design code for a program that converts from binary number to decimal and vice versa. This is what i have so far: print "Welcome to the binary and decimal converter"loop = Truewhile loop: bord = raw_input("Enter b for binary or d decimal or exit to exit")if bord == "b":

Re: [Tutor] improving speed using and recalling C functions

2014-04-11 Thread Gabriele Brambilla
Ok guys, when I wrote that email I was excited for the apparent speed increasing (it was jumping the bottleneck for loop for the reason peter otten outlined). Now, instead the changes, the speed is not improved (the code still running from this morning and it's at one forth of the dataset). What c

Re: [Tutor] improving speed using and recalling C functions

2014-04-11 Thread Danny Yoo
On Fri, Apr 11, 2014 at 1:01 PM, Gabriele Brambilla wrote: > Yes, > but I want to make a C extension to run faster a function from > scipy.interpolate (interp1d) > > It woulldn't change anything? This is precisely why you want to drive your optimization based on what the profiler is telling you.

Re: [Tutor] improving speed using and recalling C functions

2014-04-11 Thread Danny Yoo
On Fri, Apr 11, 2014 at 1:01 PM, Gabriele Brambilla wrote: > Yes, > but I want to make a C extension to run faster a function from > scipy.interpolate (interp1d) Just to emphasis: I believe your goal should be: "I want to make my program fast." Your goal should probably not be: "I want to write

[Tutor] Fwd: improving speed using and recalling C functions

2014-04-11 Thread Gabriele Brambilla
I forget the reply all -- Forwarded message -- From: Gabriele Brambilla Date: 2014-04-11 16:03 GMT-04:00 Subject: Re: [Tutor] improving speed using and recalling C functions To: Peter Otten <__pete...@web.de> you are right. probably this is the problem. thanks Gabriele 2014-

Re: [Tutor] improving speed using and recalling C functions

2014-04-11 Thread Gabriele Brambilla
Yes, but I want to make a C extension to run faster a function from scipy.interpolate (interp1d) It woulldn't change anything? thanks Gabriele 2014-04-11 14:47 GMT-04:00 Alan Gauld : > On 11/04/14 09:59, Peter Otten wrote: > >> Gabriele Brambilla wrote: >> >> Anyway I would like to try to sp

Re: [Tutor] improving speed using and recalling C functions

2014-04-11 Thread Peter Otten
Gabriele Brambilla wrote: > ok, it seems that the code don't enter in this for loop > > for gammar, MYMAP in zip(gmlis, MYMAPS): > > I don't understand why. You have two variables with similar names, gmlis and gmils: >> gmlis = [] >> gmils=[my_parts[7], my_part

Re: [Tutor] Range within a range

2014-04-11 Thread bob gailer
On 4/11/2014 1:13 PM, Andoni Gorostiza wrote: Hi tutor. I need your help with something I don't understand. In the tutorial, it mentions an example of a range within a range. I'll keep it simplified. How exactly does this work? I'll provide a few examples. >>> for x in range(0,5): ...for n in

Re: [Tutor] How to make comparison work

2014-04-11 Thread Gregg Martinson
Excellent. I guess I never read through the class stuff in learning python(its a great book, but very detailed) Now I know better! -- http://about.me/greggmartinson On Fri, Apr 11, 2014 at 3:32 AM, Peter Otten <__pete...@web.de> wrote: > Gregg Martinson wrote: > > > I have been working thr

[Tutor] Range within a range

2014-04-11 Thread Andoni Gorostiza
Hi tutor. I need your help with something I don't understand. In the tutorial, it mentions an example of a range within a range. I'll keep it simplified. How exactly does this work? I'll provide a few examples. >>> for x in range(0,5): ...for n in range(0,5): ...          print(x) >>> for x in

Re: [Tutor] improving speed using and recalling C functions

2014-04-11 Thread Alan Gauld
On 11/04/14 09:59, Peter Otten wrote: Gabriele Brambilla wrote: Anyway I would like to try to speed it up using C functions ... posted looks like it has great potential for speed-up by replacing the inner loops with numpy array operations. And in case its not obvious much(most?) of numPy con

Re: [Tutor] improving speed using and recalling C functions

2014-04-11 Thread Gabriele Brambilla
this is the profile for a sample of 1000 elements Fri Apr 11 10:21:21 2014restats 31594963 function calls in 103.708 seconds Ordered by: internal time List reduced from 47 to 20 due to restriction <20> ncalls tottime percall cumtime percall filename:lineno(function)

Re: [Tutor] improving speed using and recalling C functions

2014-04-11 Thread Gabriele Brambilla
ok modifying the for in this way (zipping an array of matrix drive it crazy) it works dko=0 for gammar in gmils: omC = (1.5)*(gammar**3)*c/(rho*rlc) gig = omC*hcut/eVtoErg #check the single emission

Re: [Tutor] improving speed using and recalling C functions

2014-04-11 Thread Gabriele Brambilla
ok, it seems that the code don't enter in this for loop for gammar, MYMAP in zip(gmlis, MYMAPS): I don't understand why. Thanks Gabriele 2014-04-11 9:56 GMT-04:00 Gabriele Brambilla : > Hi, I'm sorry but there is a big problem. > the code is producing empty file.dat. > > I think it's because

Re: [Tutor] improving speed using and recalling C functions

2014-04-11 Thread Gabriele Brambilla
Hi, I'm sorry but there is a big problem. the code is producing empty file.dat. I think it's because of this that previously I have done that strange trick of myinternet... So: for my_line in open('data.dat'): myinternet = [] gmlis = [] print('r

Re: [Tutor] improving speed using and recalling C functions

2014-04-11 Thread Gabriele Brambilla
Hi Danny, I'm quiet impressed. the program takes near 30 minutes instead of more than 8 hours! this is the profile: Fri Apr 11 09:14:04 2014restats 19532732 function calls in 2105.024 seconds Ordered by: internal time ncalls tottime percall cumtime percall filename:lineno

Re: [Tutor] improving speed using and recalling C functions

2014-04-11 Thread Gabriele Brambilla
I think I have Cython already installed with Anaconda. How it works? Thanks Gabriele 2014-04-11 8:16 GMT-04:00 Albert-Jan Roskam : > > > From: Gabriele Brambilla > >To: Danny Yoo > >Cc: python tutor > >Sent: Friday, April 11, 2014 5:30 AM > >Subject: Re: [T

Re: [Tutor] improving speed using and recalling C functions

2014-04-11 Thread Albert-Jan Roskam
> From: Gabriele Brambilla >To: Danny Yoo >Cc: python tutor >Sent: Friday, April 11, 2014 5:30 AM >Subject: Re: [Tutor] improving speed using and recalling C functions >   > > >Hi Danny, >I followed your suggestion. >Tomorrow morning I will run this new version

Re: [Tutor] improving speed using and recalling C functions

2014-04-11 Thread Peter Otten
Gabriele Brambilla wrote: > Anyway I would like to try to speed it up using C functions (and maybe > comparing the resuts of the two profile in the end) I can't help you on your chosen path, but let me emphasise that the code you posted looks like it has great potential for speed-up by replacing

Re: [Tutor] How to make comparison work

2014-04-11 Thread Peter Otten
Gregg Martinson wrote: > I have been working through a fairly simple process to teach myself python > and I am running into a problem with a comparison. Can anyone tell me > where I am going wrong? > > #!/usr/bin/env python > > class Team(object): > code = "" > opponents_debated=[] >

Re: [Tutor] How to make comparison work

2014-04-11 Thread Alan Gauld
On 11/04/14 00:27, Gregg Martinson wrote: I have been working through a fairly simple process to teach myself python and I am running into a problem with a comparison. Can anyone tell me where I am going wrong? #!/usr/bin/env python class Team(object): code = "" opponents_debated=[]

[Tutor] How to make comparison work

2014-04-11 Thread Gregg Martinson
I have been working through a fairly simple process to teach myself python and I am running into a problem with a comparison. Can anyone tell me where I am going wrong? #!/usr/bin/env python class Team(object): code = "" opponents_debated=[] wins=0 losses=0 competitors=[]

[Tutor] Fwd: Refining Code

2014-04-11 Thread Danny Yoo
Forwarding to tutor; need to sleep tonight. -- Forwarded message -- From: Saba Usmani Date: Thu, Apr 10, 2014 at 11:35 PM Subject: Re: [Tutor] Refining Code To: Danny Yoo Hi, Yes I did use copy and paste sometimes- is that bad? How could you tell and what are the similarities