[Numpy-discussion] Tests for empty arrays
Tue May 6 11:45:01 CDT 2008
2008/5/6 Andy Cheesman <Andy.email@example.com>:
> I was wondering if anyone could shed some light on how to distinguish an
> empty array of a given shape and an zeros array of the same dimensions.
An "empty" array, that is, an array returned by the function empty(),
just means an uninitialized array. The only difference between it and
an array returned by zeros() is the values in the array: from zeros()
they are, obviously, all zero, while from empty() they can be
anything, including zero(). In practice they tend to be crazy numbers
of order 1e300 or 1e-300, but one can't count on this.
As a general rule, I recommend against using empty() on your first
pass through the code. Only once your code is working and you have
tests running should you consider switching to empty() for speed
reasons. In fact, if you want to use empty() down the road, it may
make sense to initialize your array to zeros()/0., so that if you ever
use the values, the NaNs will propagate and become obvious.
Unfortunately, some CPUs implement NaNs in software, so there can be a
huge speed hit.
More information about the Numpy-discussion