On Tue, 17 Aug 2010 10:22:27 -0500, Robert Kern wrote: > On 8/16/10 11:10 PM, Steven D'Aprano wrote: >> On Mon, 16 Aug 2010 22:56:20 -0500, Robert Kern wrote: >> >>> On 8/16/10 9:29 PM, Roy Smith wrote: >>>> In article<i4cqg0$ol...@lust.ihug.co.nz>, >>>> Lawrence D'Oliveiro<l...@geek-central.gen.new_zealand> wrote: >>>> >>>>> In message<roy-ee1b7f.21001716082...@news.panix.com>, Roy Smith >>>>> wrote: >>>>> >>>>>> 5) real intensity[160.0 : 30.0 : 0.01] >>>>> >>>>> How many elements in that array? >>>>> >>>>> a) 2999 >>>>> b) 3000 >>>>> c) neither of the above >>>> >>>> c) neither of the above. More specifically, 13,001 (if I counted >>>> correctly). >>> >>> 13000, actually. Floating point is a bitch. >>> >>> [~/Movies] >>> |1> import numpy >>> >>> [~/Movies] >>> |2> len(numpy.r_[160.0:30.0:-0.01]) >>> 13000 >> >> >> Actually, the answer is 0, not 13000, because the step size is given as >> 0.01, not -0.01. >> >>>>> import numpy >>>>> len(numpy.r_[160.0:30.0:-0.01]) >> 13000 >>>>> len(numpy.r_[160.0:30.0:0.01]) >> 0 > > Roy wasn't using numpy/Python semantics but made-up semantics (following > Martin Gregorie's made-up semantics to which he was replying) which > treat the step size as a true size, not a size and direction. The > direction is determined from the start and stop parameters. It's an > almost-reasonable design.
That wasn't a made-up example: AFAICR and ignoring a missing semi-colon it was an Algol 68 snippet. The semantics of the for statement and the use of lwb and upb operators to extract the bounds from a 1-dimensional array are correct A68, but OTOH its a very long time since I last programmed in that language. I used that rather than Python because Algol 68 supports the non-zero lower bound and treats the array limits as attributes of the array. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | -- http://mail.python.org/mailman/listinfo/python-list