[Numpy-discussion] linspace upper bound not met?
Bill Baxter
wbaxter at gmail.com
Mon Aug 21 02:45:59 CDT 2006
I was porting some code over from matlab in which I relied on the upper
bound of linspace to be met exactly.
It turns out that it isn't always exactly met in numpy.
In [390]: filter(lambda x: x[1]!=0.0, [ (i,1.0-numpy.linspace(0,1,i)[-1])
for i in range(2,200) ])
Out[390]:
[(50, 1.1102230246251565e-016),
(99, 1.1102230246251565e-016),
(104, 1.1102230246251565e-016),
(108, 1.1102230246251565e-016),
(162, 1.1102230246251565e-016),
(188, 1.1102230246251565e-016),
(197, 1.1102230246251565e-016),
(198, 1.1102230246251565e-016)]
I know it's not a good idea to count on floating point equality in general,
but still it doesn't seem too much to expect that the first and last values
returned by linspace are exactly the values asked for if they both have
exact floating point representations.
--bb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20060821/d435f4f8/attachment.html
More information about the Numpy-discussion
mailing list