Re: [Tutor] Plotting a Linear Equation
On Thu, Sep 23, 2010 at 10:51 PM, Corey Richardson wrote: > Hello tutors. Probably the wrong mailing list, but someone might know. > I want to use matplotlib (or similar) to plot an equation in > slope-intercept (y=mx+b) or standard form (Ax + By = C). As far as I've read > and tested, you can only plot with a series of points. I could make two > points out of those manually, but I was wondering if anyone knew of an > easier way. Thanks. > You could just have your program compute the x- and y- intercepts, then plug them into matplotlib. Am I correct in that? -- Greg Bair gregb...@gmail.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] pure function problem
On Fri, Sep 24, 2010 at 1:43 AM, Roelof Wobben wrote: > > > > >> From: st...@pearwood.info >> To: tutor@python.org >> Date: Fri, 24 Sep 2010 13:00:40 +1000 >> Subject: Re: [Tutor] pure function problem >> >> Roelof, please learn to delete unnecessarily quoted text. There's no >> need to quoted the entire discussion every time you answer. >> >> On Fri, 24 Sep 2010 06:20:25 am Roelof Wobben wrote: >> >>> time = tijd() >> [...] >>> print time(uitkomst) >> >> Why are you calling time as a function, when it is a tijd instance? >> >> >> >> >> -- >> Steven D'Aprano >> ___ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor > > > Hello Steve, > > I found this in my tutorial. > > 13.8. Instances as return values¶ > Functions can return instances. For example, find_center takes a Rectangle as > an argument and returns a Point that contains the coordinates of the center > of the Rectangle: > def find_center(box): > p = Point() > p.x = box.corner.x + box.width/2.0 > p.y = box.corner.y - box.height/2.0 > return p > To call this function, pass box as an argument and assign the result to a > variable: center = find_center(box) print_point(center) > (50.0, 100.0) > > > So i followed it but appearently not the good way. > > Roelof > > ___ > Tutor maillist - tu...@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > If I'm understanding the question correctly(I skim alot) It looks like you're trying to use a class like a function. If you had: class tijd(object): def bob: pass then you would call bob from the class in an instance like this: aclass = tijd() calledClassFunction = aclass.bob but if you have aclass = tijd() calledClassFunction = aclass.notbob then you can't access it, because notbob is not in tijd(), therefore not in aclass, which is still the same as being tijd().bob, you just have to call the class instance before the function can be accessed. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] pure function problem
On 2:59 PM, Roelof Wobben wrote: From: st...@pearwood.info On Fri, 24 Sep 2010 06:20:25 am Roelof Wobben wrote: time =ijd() [...] print time(uitkomst) Why are you calling time as a function, when it is a tijd instance? Hello Steve, I found this in my tutorial. 13.8. Instances as return values¶ Functions can return instances. For example, find_center takes a Rectangle as an argument and returns a Point that contains the coordinates of the center of the Rectangle: def find_center(box): p =oint() p.x =ox.corner.x + box.width/2.0 p.y =ox.corner.y - box.height/2.0 return p To call this function, pass box as an argument and assign the result to a variable: center =ind_center(box) print_point(center) (50.0, 100.0) So i followed it but appearently not the good way. Roelof There's a big difference between print_point() and print time(). print_point() in your tutorial is a function, presumably defined someplace else. You used print time(), (no underscore), which uses the print statement, and tries to call a function called time(). Since you defined time as an instance of your class, and didn't do anything special, it's not callable. DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] pure function problem
> Date: Fri, 24 Sep 2010 06:29:03 -0400 > From: da...@ieee.org > To: rwob...@hotmail.com > CC: tutor@python.org > Subject: Re: [Tutor] pure function problem > > On 2:59 PM, Roelof Wobben wrote: >> >> >> >>> From: st...@pearwood.info >>> >>> On Fri, 24 Sep 2010 06:20:25 am Roelof Wobben wrote: >>> time =ijd() >>> [...] print time(uitkomst) >>> Why are you calling time as a function, when it is a tijd instance? >>> >>> >> >> Hello Steve, >> >> I found this in my tutorial. >> >> 13.8. Instances as return values¶ >> Functions can return instances. For example, find_center takes a Rectangle >> as an argument and returns a Point that contains the coordinates of the >> center of the Rectangle: >> def find_center(box): >> p =oint() >> p.x =ox.corner.x + box.width/2.0 >> p.y =ox.corner.y - box.height/2.0 >> return p >> To call this function, pass box as an argument and assign the result to a >> variable: > center =ind_center(box) > print_point(center) >> (50.0, 100.0) >> >> >> So i followed it but appearently not the good way. >> >> Roelof > There's a big difference between print_point() and print time(). > > print_point() in your tutorial is a function, presumably defined > someplace else. > > You used print time(), (no underscore), which uses the print statement, > and tries to call a function called time(). > > Since you defined time as an instance of your class, and didn't do > anything special, it's not callable. > > DaveA > Oke, I see it now. I have to us a function that i had to write a few questions before. Thanks everybody Roelof ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Plotting a Linear Equation
-Original Message- From: Greg To: tutor Sent: Fri, Sep 24, 2010 3:29 am Subject: Re: [Tutor] Plotting a Linear Equation On Thu, Sep 23, 2010 at 10:51 PM, Corey Richardson wrote: Hello tutors. Probably the wrong mailing list, but someone might know. I want to use matplotlib (or similar) to plot an equation in slope-intercept (y=mx+b) or standard form (Ax + By = C). As far as I've read and tested, you can only plot with a series of points. I could make two points out of those manually, but I was wondering if anyone knew of an easier way. Thanks. You could just have your program compute the x- and y- intercepts, then plug them into matplotlib. Am I correct in that? -- Greg Bair gregb...@gmail.com __ Yes, you are correct. That's what I planned on doing if I couldn't plug the equation right into matplotlib. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] list.append(x) but at a specific 'i'
On Wed, Sep 22, 2010 at 9:47 PM, Steven D'Aprano wrote: > On Wed, 22 Sep 2010 08:30:09 am Norman Khine wrote: > >> hello, how do i extend a python list but from a given [i], > > Do you mean to modify the list in place, like append() and extend() do, > or do you mean to create a new list, like + does? > > >> for example: >> >>> a = ['a', 'b', 'e'] >> >>> b = ['c', 'd'] >> >>> >> >>> a + b >> >> ['a', 'b', 'e', 'c', 'd'] >> >> >> but i want to put the items of 'b' at [-2] for example. > > When you ask a question, it usually helps to show the output you *want*, > not the output you *don't want*, rather than to make assumptions about > what other people will understand. > > When you say that you want the items of b *at* -2, taken literally that > could mean: > a = ['a', 'b', 'e'] b = ['c', 'd'] a.insert(-2+1, b) print(a) > ['a', 'b', ['c', 'd'], 'e'] > > Note that the items of b are kept as a single item, at the position you > ask for, and the index you pass to insert() is one beyond when you want > them to appear. > > To create a new list, instead of insert() use slicing: > a[:-2+1] + [b] + a[-2+1:] > ['a', 'b', ['c', 'd'], 'e'] > > > If you want the items of b to *start* at -2, since there are exactly two > items, extend() will do the job for in-place modification, otherwise +. > But you already know that, because that was your example. > > If you want the items of b to *end* at -2, so that you get > ['a', 'b', 'c', 'd', 'e'] then you could use repeated insertions: > > for c in b: > a.insert(-2, c) > > but that will likely be slow for large lists. Better to use slicing. To > create a new list is just like the above, except you don't create a > temporary list-of-b first: > a[:-2+1] + b + a[-2+1:] > ['a', 'b', 'c', 'd', 'e'] > > > To do it in place, assign to a slice: > a[-2:-2] = b print(a) > ['a', 'c', 'd', 'b', 'e'] thanks for all the replies, and the detailed information > > > > -- > Steven D'Aprano > ___ > Tutor maillist - tu...@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- ˙uʍop ǝpısdn p,uɹnʇ pןɹoʍ ǝɥʇ ǝǝs noʎ 'ʇuǝɯɐן sǝɯıʇ ǝɥʇ puɐ 'ʇuǝʇuoɔ ǝq s,ʇǝן ʇǝʎ %>>> "".join( [ {'*':'@','^':'.'}.get(c,None) or chr(97+(ord(c)-83)%26) for c in ",adym,*)&uzq^zqf" ] ) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor