Python "why" questions
Steven D'Aprano
steve-REMOVE-THIS at cybersource.com.au
Tue Aug 17 00:10:31 EDT 2010
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$olf$3 at lust.ihug.co.nz>,
>> Lawrence D'Oliveiro<ldo at geek-central.gen.new_zealand> wrote:
>>
>>> In message<roy-EE1B7F.21001716082010 at 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
--
Steven
More information about the Python-list
mailing list