[Numpy-discussion] Numpy float precision vs Python list float issue
Mon Apr 20 21:43:24 CDT 2009
Ruben Salvador wrote:
> Anyway, this 'deepcopy' really surprised me. I have now looked for it
> and I think I get an idea of it, though I wouldn't expect this
> difference in behavior to happen. From "my logical" point of view a
> copy is a copy, and if I find a method called copy() I can only expect
> it to...copy (whether I am copying compound or "simple" objects!!).
> This comment is only for the shake of curiosity. I guess maybe it is
> just my lack of knowledge in programming in general and this is such a
> needed difference in copy behavior.
That's something which is related to python. Python lists are mutable,
meaning that when you modify one variable, you modify it in place.
Simply said, copying a list means creating a new contained with the
*same* items, and a deepcopy means creating a new container with a
(potentially recursive) copy of every item.
> On Mon, Apr 20, 2009 at 7:21 PM, John Gleeson <email@example.com
> <mailto:firstname.lastname@example.org>> wrote:
> On 2009-04-20, at 10:04 AM, David Cournapeau wrote:
> > Yes, it is legitimate and healthy to worry about the difference
> - but
> > the surprising thing really is the list behavior when you are
> used to
> > numerical computation :) And I maintain that the algorithms are not
> > the same in both operations.
> It's not? Would you please mind commenting this a little bit?
they are not because of the conversion to numpy array. And maybe other
implementation details. The thing which matters is which operations are
done in the hardware, and that's really difficult to control exactly
once you have two implementations. The same code could give different
results on different OS, different platforms, etc... The main point is
to remember that you can't expect exact results with floating point
units, and that for all practical purpose, you can't guarantee two
implementations to be the same. For example, python float behavior and
numpy array behavior may be different w.r.t FPU exceptions, depending on
the environment and your settings.. They *could* be equal, but that
would most likely be an accident.
More information about the Numpy-discussion