Re: [Edu-sig] Truth values and comparisons

2006-11-06 Thread Arthur
Scott David Daniels wrote: >>Though I guess we are all allowed to define "sound programming" for >>ourselves. >> >> > >With the exception you pointed out about space shuttles. > > if sum(abs(the_array)) != 0: go ahead Am I still blowing up anything, potentially?? Still preferring some

Re: [Edu-sig] Truth values and comparisons

2006-11-05 Thread Scott David Daniels
Arthur wrote: > > ... Is concerning myself with this distinction sound programming, or is > the hard core answer more to the effect what works works, what doesn't > doesn't - and one should focus only on that, and perhaps the performance > impact of available alternatives? For my money (and th

Re: [Edu-sig] Truth values and comparisons

2006-11-05 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: > I've not used .any or .all, but having just taught my CS1 students about > boolean operators, I was reminded that Python works as the following example > describes: > > x = a and b > # if both a and b are true, x is assigned b, otherwise x is assigned a You are mislead

Re: [Edu-sig] Truth values and comparisons

2006-10-30 Thread Arthur
Dan Crosta wrote: > >be careful: > > >>> a = [1, 0, -1] > >>> if a: print "true" >true > >>> if sum(a) != 0: print "true > > Oops. Definitely keep me away from space shuttle projects ;) Art ___ Edu-sig mailing list Edu-sig@python.org http://mail.p

Re: [Edu-sig] Truth values and comparisons

2006-10-30 Thread Dan Crosta
Arthur wrote: > if sum(x) !=0: >use this array > else: >use other array. be careful: >>> a = [1, 0, -1] >>> if a: print "true" true >>> if sum(a) != 0: print "true" that's why it's probably safer and more readable to use any() and all(), which i believe were both introduced to __bu

Re: [Edu-sig] Truth values and comparisons

2006-10-30 Thread Arthur
John Zelle wrote: >This is why in teaching I prefer to use explicit tests: > >if x != 0: >do something > >Rather than > >if x: >do something > > > Yeah, so in the case I am looking at there is a branching based on whether either of 2 arrays are all zeros. So to achieve numpy compatib

Re: [Edu-sig] Truth values and comparisons

2006-10-30 Thread Arthur
John Zelle wrote: >On Monday 30 October 2006 10:49 am, Arthur wrote: > > >> >>thanks, but having some trouble: >> >>> import Numeric as N >> >>> a=N.array([0,0,0]) >> >>> b=N.array([0,0,1]) >> >>> a and b >> >>array([0, 0, 0]) >> >> > >This tells me that a zero array is being treated as Fals

Re: [Edu-sig] Truth values and comparisons

2006-10-30 Thread John Zelle
On Monday 30 October 2006 10:49 am, Arthur wrote: > [EMAIL PROTECTED] wrote: > >I've not used .any or .all, but having just taught my CS1 students about > > boolean operators, I was reminded that Python works as the following > > example describes: > > > >x = a and b > ># if both a and b are true,

Re: [Edu-sig] Truth values and comparisons

2006-10-30 Thread Arthur
[EMAIL PROTECTED] wrote: > >I've not used .any or .all, but having just taught my CS1 students about >boolean operators, I was reminded that Python works as the following example >describes: > >x = a and b ># if both a and b are true, x is assigned b, otherwise x is assigned a >x = 2 and 3 # x i

Re: [Edu-sig] Truth values and comparisons

2006-10-30 Thread davelist
On Monday, October 30, 2006, at 08:30AM, "Arthur" <[EMAIL PROTECTED]> wrote: > >Looking for a little education on edu-sig. > >On one hand I am feeling like a big boy, having announced today on the >vpython list that I think I have adequately accomplished the necessary >fixes to the vpython C++

[Edu-sig] Truth values and comparisons

2006-10-30 Thread Arthur
Looking for a little education on edu-sig. On one hand I am feeling like a big boy, having announced today on the vpython list that I think I have adequately accomplished the necessary fixes to the vpython C++ code to accomplish compatibility with the newly released numpy 1.0, and in a way tha