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 something along

Re: [Edu-sig] Truth values and comparisons

2006-11-05 Thread Scott David Daniels
Arthur wrote: some code with an issue addressed by Dan Crosta ... 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

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 is

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, x is

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 False (the logical extension to arrays

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 compatibility, and

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 __builtin__ in